Hello so i got this datastore script.
local stat = "Cash" --Change to your stat name
local startamount = 255 --Change to how much points the player will start out with
local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("LeaderStatSave")
--Don't worry about the rest of the code, except for line 25.
game.Players.PlayerAdded:connect(function(player)
local leader = Instance.new("Folder",player)
leader.Name = "leaderstats"
local Cash = Instance.new("IntValue",leader)
Cash.Name = "Cash"
Cash.Value = startamount
local Waves = Instance.new("IntValue",leader)
Waves.Name = "Waves"
Waves.Value = 0
local data = {}
local success, err = pcall(function()
data = ds:GetAsync(player.UserId)
end)
if success then
Cash.Value = data[1]
Waves.Value = data[2]
else
warn(err)
end
end)
game.Players.PlayerRemoving:connect(function(player)
local success, err = pcall(function()
ds:SetAsync({player.UserId, player.leaderstats.Cash.Value, player.leaderstats.Waves.Value})
end)
if success then print("Saved") else warn(err) end
end)
and for some reason i get this warning everytime i leave.
Argument 2 missing or nil
how would i fix this?