I have this script I got from a Youtube Tutorial that should save the players stats. For some reason it’s not. Any ideas?
Script -
local dss = game:GetService("DataStoreService")
local ds = dss:GetDataStore("data")
function saveData(plr)
local cash = plr.Currency.Coins.Value
pcall(function()
ds:SetAsync(plr.UserId .. "-Coins", cash)
end)
end
game.Players.PlayerAdded:Connect(function(plr)
local ls = Instance.new("Folder")
ls.Name = "Currency"
ls.Parent = plr
local cash = Instance.new("IntValue")
cash.Name = "Coins"
cash.Parent = ls
local data = nil
pcall(function()
data = ds:GetAsync(plr.UserId .. "-Coins")
end)
cash.Value = data or 0
end)
game.Players.PlayerRemoving:Connect(saveData)
game:BindToClose(function()
for i, plr in pairs(game.Players:GetPlayers()) do
saveData(plr)
end
end)