Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

LeaderStats aren't saving, whats wrong?

Asked by
Burobuu 18
5 years ago

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)
0
Changing that didnt work either. Burobuu 18 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)
0
OP wasn't? User#19524 175 — 5y
0
?? SBlankthorn 329 — 5y
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. Burobuu 18 — 5y
0
Umm That should work. SBlankthorn 329 — 5y
View all comments (3 more)
0
Are you able to make a back up copy of your game and invite me to team create so i can check? SBlankthorn 329 — 5y
0
@Buro Studio Access to API probably isn't ticked User#19524 175 — 5y
0
Ye I said to make sure to do that, cause that script is tested /: SBlankthorn 329 — 5y
Ad

Answer this question