The pcall() Devforum Link: https://devforum.roblox.com/t/pcall-x...
--------------------------------------------------------------------------------
----- The Script:
local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("YOUR_DATASTORE_NAME")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local YOUR_CURRENCY_HERE = Instance.new("IntValue")
YOUR_CURRENCY_HERE.Name = "YOUR_CURRENCY_NAME_HERE"
YOUR_CURRENCY_HERE.Parent = leaderstats
local data
local success, errormessage = pcall(function()
data = dataStore:GetAsync(player.UserId.."-your_currency_name")
end)
if success then
YOUR_CURRENCY_HERE.Value = data
else
print("There was an error.")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success, errormessage = pcall(function()
dataStore:SetAsync(plr.UserId.."-your_currency_name", plr.leaderstats.YOUR_CURRENCY_NAME_HERE.Value)
end)
if success then
print("Successfully saved Player Data!")
else
print("There was an error while saving player data!")
warn(errormessage)
end
end)
------------------------------------------------------------------------------------
🚨🚨My Youtube Channel (Please subscribe I'm trying to hit 5k!)🚨🚨: / @jackthemonster
Join my Roblox Group here! https://web.roblox.com/groups/5028136...
Follow my NEW Roblox Account! https://web.roblox.com/users/36998870...
---------------------------------------------------------------------------------------