hello developper!
i need you
my script does not work because
look at my picture:
my script:
local DataStore = game:GetService("DataStoreService")
local myDataStore = DataStore:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local Coins = Instance.new("NumberValue")
Coins.Name = "Coins"
Coins.Parent = leaderstats
Coins.Value = 0
local cc = Instance.new("IntValue",plr)
cc.Name = "CashCollected"
local robbing = Instance.new("BoolValue",plr)
robbing.Name = "Robbing"
robbing.Value = false
local data
local success, errormessage = pcall(function()
data = myDataStore:GetASync(plr.UserId.."-Coins")
end)
if success then
Coins.Value = data
else
print("There was an error while giving Player Data.")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success, errormessage = pcall(function()
myDataStore:SetASync(plr.UserId.."-Coins", plr.leaderstats.Coins.Value)
end)
if success then
print("Player Data successfully saved!")
else
print("There was an error while saving Player Data.")
warn(errormessage)
end
end)
thank you in advance