I'm trying to make a DataStore script but, my values won't save. I'm also watching tutrials on youtube on how to code DataStores to check if some of the parts of my code are wrong but still, no luck. Is there something wrong with the code?
Server Script:
local DataStore = game:GetService("DataStoreService")
local DS = DataStore:GetDataStore("CoinsAndGems")
game.Players.PlayerAdded:Connect(function(plr)
local leaderboard = Instance.new("Folder", plr)
leaderboard.Name = "leaderstats"
local money = Instance.new("IntValue", leaderboard)
money.Name = "Money"
local key = "user"..plr.UserId
local savedValues = DS:GetAsync(key)
if savedValues then
money.Value = savedValues
else
local saveValues = (money.Value)
DS:SetAsync(key, saveValues)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local leaderboard = plr:WaitForChild("leaderstats")
local money = leaderboard.Money
local key = "user-"..plr.UserId
DS:SetAsync(key, money.Value)
end)
