Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

LeaderStats aren't saving, whats wrong?

oof, I was trying to make a save function for my new money system regarding the leaderstats. I guess I did something wrong...again.

Current script Located in workspace

local DS = game:GetService("DataStoreService"):GetDataStore("Points")
function PlayerAdded(player)
    local folder = Instance.new("Folder",player)
 folder.Name= "leaderstats"
 local Balance = Instance.new("IntValue",folder)
 Balance.Name="Balance"
 Balance.Value = 0 
while true do
  wait(2.5)
  Balance.Value = Balance.Value + 1
DS:SetAsync(player.userId.."_DS", Balance.Value)
end
end
game.Players.PlayerAdded:Connect(PlayerAdded)

Script before I attempted to save Located in workspace

function PlayerAdded(player)
    local folder = Instance.new("Folder",player)
 folder.Name= "leaderstats"
 local Balance = Instance.new("IntValue",folder)
 Balance.Name="Balance"
 Balance.Value = 0 
while true do
  wait(2.5)
  Balance.Value = Balance.Value + 1
end
end

game.Players.PlayerAdded:Connect(PlayerAdded)

1 comment

0

Changing that didnt work either.

1 answer

The error is, you don't have a datastore. Without it, when the player leaves, their point value will return to 0. Use it to make sure they keep their points when they rejoin. (Also make sure Enable Access to API Services is ticked)

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("Points")

game.Players.PlayerAdded:Connect(function(plr)
	local folder = Instance.new("Folder", plr)
	folder.Name = "leaderstats"
	local Balance = Instance.new("IntValue", folder)
	Balance.Name = "Balance"
	Balance.Value = 0
	Balance.Value = ds1:GetAsync(plr.UserId) or 0
	ds1:SetAsync(plr.UserId, Balance.Value)
	
	Balance.Changed:Connect(function()
		ds1:SetAsync(plr.UserId, Balance.Value)
	end)
end)

7 comments

0

OP wasn't?

0

??

0

Oof, the script didnt say it had errors and I didnt see any visible errors either, yet it still didnt work. I changed my Balance using the explorer and re-tested it again but that didnt save.

0

Umm That should work.

0

Are you able to make a back up copy of your game and invite me to team create so i can check?

0

@Buro Studio Access to API probably isn't ticked

0

Ye I said to make sure to do that, cause that script is tested /:

This discussion is preserved as it was. New answers, comments, and votes are closed.