This is supposed to be a DataStore script I did from a tutorial but it doesn't seem to work. Any idea what's wrong?
Here's part one of the script:
local DataStore = game:GetService("DataStoreService"):GetDataStore("LolWhyDa")
game.Players.PlayerAdded:connect(function(player)
local stats = Instance.new("IntValue", player)
stats.Name = "leaderstats"
local points = Instance.new("IntValue", stats)
points.Name = "Points"
local coins = Instance.new("IntValue", stats)
coins.Name = "Coins"
local key = "user-"..player.userId
local savedValues = DataStore:GetAsync(key)
if savedValues then
--Save Format: {points, coins}
points.Value = savedValues.Value[1]
coins.Value = savedValues.Value[2]
else
local valuesToSave = {points.Value, coins.Value}
DataStore:SetAsync(key, valuesToSave)
end
end)
Part 2, located in a seperate script
local DataStore = game:GetService("DataStoreService"):GetDataStore("LolWhyDa")
game.Players.PlayerRemoving:connect(function(player)
local key = "user-"..player.userId
--Save key: {points, coins}
local valuesToSave = {player.leaderstats.Points.Value, player.leaderstats.Coins.Value}
DataStore:SetAsync(key, valuesToSave)
end)
both scripts are in ServerScriptService.

2 comments
leaderstats must be a model
I did that, still didn't save!