local stat = "Cash" --Change to your stat name
local startamount = 0 --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 = ds:GetAsync(player.UserId) or startamount
ds:SetAsync(player.UserId, Cash.Value)
Cash.Changed:connect(function()
ds:SetAsync(player.UserId, Cash.Value)
end)
end)
game.Players.PlayerRemoving:connect(function(player)
ds:SetAsync(player.UserId, player.leaderstats.Cash.Value) --Change "Points" to the name of your leaderstat.
end)
and for some reason i get this
“DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 3837598027 - Studio” how do i fix this.
This part causes that to happen because your basically saving the already saved data and saving the data every time Cash value changes causing too many saves in the short span of time.
local stat = "Cash" --Change to your stat name
local startamount = 0 --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 = ds:GetAsync(player.UserId) or startamount
end)
game.Players.PlayerRemoving:connect(function(player)
ds:SetAsync(player.UserId, player.leaderstats.Cash.Value) --Change "Points" to the name of your leaderstat.
end)