Hello I have been struggling to make a leaderstats script work.
local dsService = game:GetService("DataStoreService")
local ds = dsService:GetDataStore("CashStats")
local ds1 = dsService:GetDataStore("KillsStats")
local ds2 = dsService:GetDataStore("AllCashStats")
local ds3 = dsService:GetDataStore("WinsStats")
local ds4 = dsService:GetDataStore("RKStats")
game.Players.PlayerAdded:Connect(function(plr)
local folder = Instance.new("Folder", plr)
folder.Name = "Stats"
local currency = Instance.new("IntValue", plr.Stats)
currency.Name = "Cash"
currency.Value = ds:GetAsync(plr.UserId) or 0
currency.Changed:Connect(function()
ds:SetAsync(plr.UserId, currency.Value)
local currency2 = Instance.new("IntValue", plr.Stats)
currency2.Name = "Kills"
currency2.Value = ds1:GetAsync(plr.UserId) or 0
currency2.Changed:Connect(function()
ds1:SetAsync(plr.UserId, currency2.Value)
local currency3 = Instance.new("IntValue")
currency3.Parent = plr.Stats
currency3.Name = "AllCash"
currency3.Value = ds2:GetAsync(plr.UserId) or 0
currency3.Changed:Connect(function()
ds2:SetAsync(plr.UserId, currency3.Value)
local currency4 = Instance.new("IntValue")
currency4.Parent = plr.Stats
currency4.Name = "Wins"
currency4.Value = ds3:GetAsync(plr.UserId) or 0
currency4.Changed:Connect(function()
ds3:SetAsync(plr.UserId, currency4.Value)
local currency5 = Instance.new("IntValue")
currency5.Parent = plr.Stats
currency5.Name = "RoundKills"
currency5.Value = ds4:GetAsync(plr.UserId) or 0
currency5.Changed:Connect(function()
ds4:SetAsync(plr.UserId, currency5.Value)
end)
end)
end)
end)
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
ds:SetAsync(plr.UserId, plr.Stats.Cash.Value)
end)
game.Players.PlayerRemoving:Connect(function(plr)
ds1:SetAsync(plr.UserId, plr.Stats.Kills.Value) -- Kills is not a valid member of Stats
end)
game.Players.PlayerRemoving:Connect(function(plr)
ds2:SetAsync(plr.UserId, plr.Stats.AllCash.Value) -- AllCash is not a valid member of Stats
end)
game.Players.PlayerRemoving:Connect(function(plr)
ds3:SetAsync(plr.UserId, plr.Stats.Wins.Value) -- Wins is not a valid member of Stats
end)
game.Players.PlayerRemoving:Connect(function(plr)
ds4:SetAsync(plr.UserId, plr.Stats.RoundKills.Value) -- RoundKills is not a valid member of Stats
end)
game.Players.PlayerAdded:connect(function(player)
local currency1 = player:WaitForChild("Stats").Cash
local currency2 = player:WaitForChild("Stats").Kills
local currency3 = player:WaitForChild("Stats").AllCash
local currency4 = player:WaitForChild("Stats").Wins
local currency5 = player:WaitForChild("Stats").RoundKills
player.CharacterAdded:connect(function(character)
character:WaitForChild("Humanoid").Died:connect(function()
local tag = character.Humanoid:FindFirstChild("creator")
if tag ~= nil then
if tag.Value ~= nil then
currency1.Value = currency1.Value + 0
currency2.Value = currency2.Value + 0
currency3.Value = currency3.Value + 0
currency4.Value = currency4.Value + 0
currency5.Value = currency5.Value + 0
local clone = player.PlayerGui.Kills.Frame.Template:Clone()
clone.Parent = player.PlayerGui.Kills.Frame
clone.Visible = true
wait(.5)
clone:Destroy()
end
end
end)
end)
end)
What the error is marked on the script and with what it says, Please help me.
The cash stat seems to move into Player.Stats but the others do not.
Iâm not using the leaderboard for these stats, I am using it to have stats shown on leaderboard and those in this script wonât be on the leaderboard.
Just do folder instead, you should also use currency.Parent = folder instead of using the Second argument of Instance.new(). I can see you arenât using pcalls for your datastore. So add those as well.
The thing you were doing wrong here was that you were creating the rest of the stats inside of a .Changed function, inside of a .Changed function and so on, even if your thing was to be working, it would have errored out. You were also waiting for the Folder name Stats to load, not the actual Values. Here is the fixed script.
local dsService = game:GetService("DataStoreService")
local ds = dsService:GetDataStore("CashStats")
local ds1 = dsService:GetDataStore("KillsStats")
local ds2 = dsService:GetDataStore("AllCashStats")
local ds3 = dsService:GetDataStore("WinsStats")
local ds4 = dsService:GetDataStore("RKStats")
game.Players.PlayerAdded:Connect(function(plr)
local folder = Instance.new("Folder", plr)
folder.Name = "Stats"
local currency = Instance.new("IntValue", plr.Stats)
currency.Name = "Cash"
currency.Value = ds:GetAsync(plr.UserId) or 0
currency.Changed:Connect(function() -- EDITED HERE
ds:SetAsync(plr.UserId, currency.Value)
end)
local currency2 = Instance.new("IntValue", plr.Stats)
currency2.Name = "Kills"
currency2.Value = ds1:GetAsync(plr.UserId) or 0
currency2.Changed:Connect(function() -- EDITED HERE
ds1:SetAsync(plr.UserId, currency2.Value)
end)
local currency3 = Instance.new("IntValue")
currency3.Parent = plr.Stats
currency3.Name = "AllCash"
currency3.Value = ds2:GetAsync(plr.UserId) or 0
currency3.Changed:Connect(function() -- EDITED HERE
ds2:SetAsync(plr.UserId, currency3.Value)
end)
local currency4 = Instance.new("IntValue")
currency4.Parent = plr.Stats
currency4.Name = "Wins"
currency4.Value = ds3:GetAsync(plr.UserId) or 0
currency4.Changed:Connect(function() -- EDITED HERE
ds3:SetAsync(plr.UserId, currency4.Value)
end)
local currency5 = Instance.new("IntValue")
currency5.Parent = plr.Stats
currency5.Name = "RoundKills"
currency5.Value = ds4:GetAsync(plr.UserId) or 0
currency5.Changed:Connect(function() -- EDITED HERE
ds4:SetAsync(plr.UserId, currency5.Value)
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
ds:SetAsync(plr.UserId, plr.Stats.Cash.Value)
end)
game.Players.PlayerRemoving:Connect(function(plr)
ds1:SetAsync(plr.UserId, plr.Stats.Kills.Value) -- Kills is not a valid member of Stats
end)
game.Players.PlayerRemoving:Connect(function(plr)
ds2:SetAsync(plr.UserId, plr.Stats.AllCash.Value) -- AllCash is not a valid member of Stats
end)
game.Players.PlayerRemoving:Connect(function(plr)
ds3:SetAsync(plr.UserId, plr.Stats.Wins.Value) -- Wins is not a valid member of Stats
end)
game.Players.PlayerRemoving:Connect(function(plr)
ds4:SetAsync(plr.UserId, plr.Stats.RoundKills.Value) -- RoundKills is not a valid member of Stats
end)
game.Players.PlayerAdded:connect(function(player)
local currency1 = player:WaitForChild("Stats"):WaitForChild("Cash") -- EDITED HERE
local currency2 = player:WaitForChild("Stats"):WaitForChild("Kills") -- EDITED HERE
local currency3 = player:WaitForChild("Stats"):WaitForChild("AllCash") -- EDITED HERE
local currency4 = player:WaitForChild("Stats"):WaitForChild("Wins") -- EDITED HERE
local currency5 = player:WaitForChild("Stats"):WaitForChild("RoundKills") -- EDITED HERE
player.CharacterAdded:connect(function(character)
character:WaitForChild("Humanoid").Died:connect(function()
local tag = character.Humanoid:FindFirstChild("creator")
if tag ~= nil then
if tag.Value ~= nil then
currency1.Value = currency1.Value + 0
currency2.Value = currency2.Value + 0
currency3.Value = currency3.Value + 0
currency4.Value = currency4.Value + 0
currency5.Value = currency5.Value + 0
local clone = player.PlayerGui.Kills.Frame.Template:Clone()
clone.Parent = player.PlayerGui.Kills.Frame
clone.Visible = true
wait(.5)
clone:Destroy()
end
end
end)
end)
end)
You are able also to make a datastore to store all of these values instead of having many Datastores for each one of these values. Hope this helped, will leave this part up to you!
Also, if you really want to have many datastores, you can just call one .PlayerRemoving function and put all your datastores in there, ds1, ds2, ds3, ds4, instead of making many of these.
Also the leaderboard doesnât really show up for me until I rename it to leaderstats, so the thing you were saying up there isnât really working for me, never did with my last scripts either.