Still have questions? Join our Discord server and get real time help.
1

# Why won't my leaderstats save?

Edited 10 days ago

So, for my game, I want my leaderstats to save. I've tried datastores and whatnot, but nothing ever works. I then resorted to using a plain leaderstats save. I reused my old leaderstat save from another one of my old games, and it worked in that game, but it doesn't work for this new game... It's a normal script in serverscriptservice. I had to repost this since I wasn't getting any more responses. Code:

CashStore = game:GetService("DataStoreService"):GetDataStore("DataStore")

function PlayerEntered(player)
repeat wait() until player.Character

local stats = Instance.new("IntValue")
stats.Parent = player

local cash = Instance.new("IntValue")
cash.Parent = stats
cash.Name = "Doubloons"

if CashStore:GetAsync("Points_"..player.Name) ~= nil then
cash.Value = CashStore:GetAsync("Points_"..player.Name)
else
cash.Value = 100
end

cash.Changed:connect(function(Val)
CashStore:SetAsync("Points_"..player.Name, Val)
end)
end



Thank you!

0
You're referencing a completely different DataStore. Use CashStore:SetAsync(). Feahren 5485 — 10d
0
@Feahren, Hello, thanks for responding. Unfortunately, I don't know what you mean. PadmeOragana 41 — 10d
0
on line on , put local behind CashStore to define it as a variable Tizzel40 225 — 10d
0
Accidentally held down Enter ! Woops ! Tizzel40 225 — 10d
0
Use Userids instead of names. You can change usernames, but not userids. Pupppy44 458 — 9d
0
What's the error? if any HxterNinja 15 — 9d
0
Also sometimes in studio, if you do a solo play test, the player can load in before the PlayerAdded connection is made. It's good to include for _,player in pairs(game.Players:GetPlayers()) do PlayerEntered(player) end HxterNinja 15 — 9d
0
@Tizzel, Thanks for responding! I did that, but it doesn't work... @Puppy, thanks for responding! Oh okay, thank you! @HxterNinja, Thanks for responding! No, there's no error. I tested it in the actual game, but it still doesn't work... PadmeOragana 41 — 8d

0
7zjh 74
10 days ago
Edited 9 days ago

Edit: You probably need to make it a player removed event. Like this:

game.Players.PlayerRemoved:Connect(function()
CashStore:SetAsync(player.UserID, cash.Value)
end)


I am sure that should do the trick!

0
Hello, thanks for responding! Thanks about the code, but the API services are on.. :C PadmeOragana 41 — 10d
0
Your code is way more cleaner than mine xd 7zjh 74 — 9d
0
Hi, thank you for editing it! Thank you, lol. Unfortunately, this doesn't work.. PadmeOragana 41 — 9d