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

Values not saving on Leaderboard?

Asked by
Cinorch 10
7 years ago
local data = game:GetService("DataStoreService"):GetDataStore("Saves")
local data = game:GetService("DataStoreService"):GetDataStore("Gold")
local settings={
    groupid = 2903819
}

game:GetService("Players").PlayerAdded:connect(function(player)
    local key = "user_"..player.UserId  

    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"
    local rank = Instance.new("StringValue", leaderstats)
    rank.Name = "Rank"
    rank.Value = player:GetRoleInGroup(settings["groupid"])
    local GetPlayerSave = data:GetAsync("user_"..player.UserId) 
    local points = Instance.new("NumberValue", leaderstats)
    points.Name = "Saves"
    if GetPlayerSave  then
    points.Value = GetPlayerSave[1]  or 0
else
    points.Value  = 0
 end

local points = Instance.new("NumberValue", leaderstats)
    points.Name = "Gold"
    if GetPlayerSave  then
    points.Value = GetPlayerSave[1]  or 0
else
    points.Value  = 0
end

end)

game:GetService("Players").PlayerRemoving:connect(function(player)
    local leaderstats = player:WaitForChild("leaderstats")
    local ToSave = {leaderstats.Saves.Value}
    local ToSave = {leaderstats.Gold.Value}
    data:SetAsync("user_"..player.UserId, ToSave)
end)

I want two things to save, Saves and Gold, both don't seem to work now despite it was working before when it had one value.

1 answer

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

I believe solving this would need folders to save each player's storage, otherwise returning the 2 values as nil.

P.S. Why do you need a 'Saves' value?

EDIT: Requested a fix by the owner

local data = game:GetService("DataStoreService"):GetDataStore("Saves")
local data = game:GetService("DataStoreService"):GetDataStore("Gold")
local settings={
    groupid = 2903819
}

game:GetService("Players").PlayerAdded:connect(function(player)
    local key = "user_"..player.UserId  

    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"
    local rank = Instance.new("StringValue", leaderstats)
    rank.Name = "Rank"
    rank.Value = player:GetRoleInGroup(settings["groupid"])
    local GetPlayerSave = data:GetAsync("user_"..player.UserId) 
    local gSaves = Instance.new("NumberValue", leaderstats) -- Replacing this part of the script.
    gSaves.Name = "Saves"
    if GetPlayerSave  then
    gSaves.Value = GetPlayerSave[1]  or 0
else
    gSaves.Value  = 0
 end

local points = Instance.new("NumberValue", leaderstats)
    points.Name = "Gold"
    if GetPlayerSave  then
    points.Value = GetPlayerSave[1]  or 0
else
    points.Value  = 0
end

end)

game:GetService("Players").PlayerRemoving:connect(function(player)
    local leaderstats = player:WaitForChild("leaderstats")
    local ToSave = {leaderstats.Saves.Value}
    local ToSave = {leaderstats.Gold.Value}
    data:SetAsync("user_"..player.UserId, ToSave)
end)

0
Just for example, also could you explain further by showing me via script of what I did wrong? It would help me a lot, thanks! Cinorch 10 — 7y
0
`local points = Instance.new("NumberValue", leaderstats) was doubled`, I believe, therefor it's been doubling. D_ctorScript 0 — 7y
0
Then how would I add a second value to the leaderboard stats in order for it to save? Cinorch 10 — 7y
0
Make a seperate variable for Line 16, instead of taking the name of Gold. D_ctorScript 0 — 7y
0
You think you could code it to show me? I really have a hard time understanding sometimes, I'm sorry! Cinorch 10 — 7y
Ad

Answer this question