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

Trouble saving leaderstats. help?

Asked by 5 years ago
Edited 5 years ago

I am having no errors yet it wont save.

local DS = game:GetService("DataStoreService"):GetDataStore("StorageThing")

game.Players.PlayerAdded:Connect(function(plr)

local stats = Instance.new("IntValue")

stats.Name = "leaderstats"

stats.Parent = plr

local Soul = Instance.new("IntValue")

Soul.Name = "Screams"

Soul.Parent = stats

local keyboi = "player-"..plr.userId

local savedvalues = DS:GetAsync(keyboi)

if savedvalues then

Soul.Value = savedvalues

else

DS:SetAsync(keyboi,Soul.Value)

end

end)



game.Players.PlayerRemoving:Connect(function(plr)

local keyboi = "player-"..plr.userId

DS:SetAsync(keyboi,{plr.leaderstats.Souls.Value})

end)
0
Are your variables correct? Do they match up according to what you have in your game? BryanFehr 133 — 5y
0
you never created a stat named "Souls" you named one "Screams" tho hellmatic 1523 — 5y

2 answers

Log in to vote
0
Answered by
hellmatic 1523 Moderation Voter
5 years ago
Edited 5 years ago
local DS = game:GetService("DataStoreService"):GetDataStore("StorageThing")

game.Players.PlayerAdded:Connect(function(plr)
    local stats = Instance.new("IntValue")
    stats.Name = "leaderstats"
    stats.Parent = plr
    local Soul = Instance.new("IntValue")
    Soul.Name = "Screams"
    Soul.Parent = stats

    local keyboi = "player-"..plr.userId
    local savedvalues = DS:SetAsync(keyboi)

    if savedvalues then
        Soul.Value = savedvalues[1] -- you're trying to set the value to a table, should be savedValues[1] instead
    else
        DS:SetAsync(keyboi,{Soul.Value})
    end
end)

game.Players.PlayerRemoving:Connect(function(plr)
    local keyboi = "player-"..plr.userId
    DS:SetAsync(keyboi, {plr.leaderstats.Screams.Value}) 
    -- you named the stat "Screams" so it would be 'plr.leaderstats.Screams'
end)
0
Hell there I am almost ready to publish my game but the thing is that my cash in leaderstats are not working,take for example it works it saves and then I do a small change in the roblox studio not even about scripts and the leaderstats are gone and back to 0. Every time u step on money it gives you 10 cash and so as I’m working in studio it most often doesn’t save and goes back to 0. pls help me Hockeylie188 0 — 4y
Ad
Log in to vote
0
Answered by 5 years ago

Where you declared the Soul variable on the bottom of your code you put leaderstats.Souls Its just an error.

0
Edit: Nvm went by the script variables. Not by the name given. Ignore the answer. thoughtless_space 95 — 5y
0
You can remove or update it if you wish User#5423 17 — 5y

Answer this question