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

How Come my DataStore/Leaderboard won't work?

Asked by 4 years ago

So I have a LeaderBoard that won't work and I don't get told why it won't work in the Developer Panel I don't exactly know why. What exactly could be going wrong?

---Script---

local DataStoreService = game:GetService("DataStoreService")

local myDataStore = DataStoreService:GetDataStore("myDataStore")

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local cash = Instance.new("IntValue")
    cash.Name = "Cash"
    cash.Value = DataStoreService:GetAsync(player.UserId) or 0

    local data
    local success, errormessage = pcall(function()
        data = myDataStore:GetAsync(player.UserId.."-cash")
    end)

    if success then
        cash.Value = data
    else
        print("There was a error whilst getting your data")
        warn(errormessage)
    end
end)

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

    local success, errormessage = pcall(function()
        myDataStore:SetAsync(player.UserId.."-cash",player.leaderstats.Cash.Value)
    end)

    if success then
        print("Player Data successfully saved!")
    else
        print("There was a error when saving data")
        warn(errormessage)
    end

end)
0
Make sure to set the cash parent to the leaderstats folder ForeverBrown 356 — 4y
0
What do you mean exactly? vincentthecat1 199 — 4y
0
Fixxed vincentthecat1 199 — 4y

3 answers

Log in to vote
1
Answered by 4 years ago

You forgot to set the Parent for your cash value like ForeverBrown stated. If you don't do it it won't be showing in the leaderboard.

Behind the if success then if statement you can add cash.Parent = leaderstats

0
Which "If success then? vincentthecat1 199 — 4y
0
Within the PlayerAdded where you create the leaderstats User#834 0 — 4y
0
So like this vincentthecat1 199 — 4y
Ad
Log in to vote
0
Answered by
Sulu710 142
4 years ago

cash.Parent = leaderstats

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

For Flowery

local DataStoreService = game:GetService("DataStoreService")

local myDataStore = DataStoreService:GetDataStore("myDataStore")

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local cash = Instance.new("IntValue")
    cash.Name = "Cash"
    cash.Parent = leaderstats
    cash.Value = 0

    local data
    local success, errormessage = pcall(function()
        data = myDataStore:GetAsync(player.UserId.."-cash")
    end)

    if success then
        cash.Value = data
    else
        print("There was a error whilst getting your data")
        warn(errormessage)
    end
end)

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

    local success, errormessage = pcall(function()
        myDataStore:SetAsync(player.UserId.."-cash",player.leaderstats.Cash.Value)
    end)

    if success then
        print("Player Data successfully saved!")
    else
        print("There was a error when saving data")
        warn(errormessage)
     end

end)
0
This? vincentthecat1 199 — 4y
0
FYI: I didn't look back at this post up until now but making a new post will not send a notification to all contributors in a post, if you need to get someone's attention again you should post a comment on an answer he/she posted. User#834 0 — 4y

Answer this question