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

How can I fix this leaderstats script?

Asked by
ultrabug 306 Moderation Voter
10 years ago

Basically I am trying to make a leaderboard, but here is what I have for it, the problem is it will not show up onto the leaderboard.

local ds=game:GetService("DataStoreService"):GetDataStore("Stats")
game.Players.PlayerAdded:connect(function(np)
    local ls=Instance.new("BoolValue")
    ls.Name="leaderstats"
    local level=Instance.new("NumberValue")
    level.Name="Level"
    local xp=Instance.new("NumberValue")
    xp.Name="XP"
    xp.Parent=ls
    local kills=Instance.new("NumberValue")
    kills.Name="Kills"
    kills.Parent=ls
    level.Parent=ls
    ls.Parent=np
    kills.Value=0
    level.Value=0
    xp.Value=0
    dsl=ds:GetAsync(tostring(np.userid).."Level")
    if dsl==nil then
        ds:SetAsync(tostring(np.userid).."Level", 0)
    else
        level.Value=ds:GetAsync(tostring(np.Userid).."Level")
    end
    dsxp=ds:GetAsync(tostring(np.userid).."XP")
    if dsxp==nil then
        ds:SetAsync(tostring(np.userid).."XP", 0)
    else
        xp.Value=ds:GetAsync(tostring(userid).."XP")
    end
end)
game.Players.PlayerRemoving:connect(function(lp)
    level=lp.leaderstats.Level
    ds:SetAsync(tostring(lp.userid).."Level", level.Value)
    ds:SetAsync(tostring(lp.userid).."XP", xp.Value)
end)
game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        local humanoid=character:WaitForChild("Humanoid")
        humanoid.Died:connect(function()
            local value=humanoid:FindFirstChild("creator")
                local kp=value.Value
                if kp~=nil then
                    kp.leaderstats.Kills.Value=kp.leaderstats.Kills.Value +1
                    kp.leaderstats.XP.Value=kp.leaderstats.XP.Value + 10
                    local xpn=kp.leaderstats.Level.Value * 100
                    if kp.leaderstats.XP.Value >= xpn then
                        kp.leaderstats.Level.Value=kp.leaderstats.Level.Value +1
                        ds:SetAsync(tostring(kp.userid).."Level", kp.leaderstats.Level.Value)
                        ds:SetAsync(tostring(kp.userid).."XP", kp.leaderstats.XP.Value)
                end
            end
        end)
    end)
end)

Thank you in advance.

0
What is the problem with it? User#2 0 — 10y
0
It will not show up onto the leaderboard. ultrabug 306 — 10y

1 answer

Log in to vote
1
Answered by
User#2 0
10 years ago

Not everything the humanoid when they die will be a creator value, so you should've kept the code inside the died event the same (unless you found another error inside of it).

That is all I noticed, if I find anything else I'll edit my answer.

0
So I should reset the values when they join the game automatically to 0? ultrabug 306 — 10y
0
Yes User#2 0 — 10y
0
Okay I will see if this will work, thank you. ultrabug 306 — 10y
0
Nope I found it, when I name the xp value I forgot to put it in a string. ultrabug 306 — 10y
View all comments (13 more)
0
Ahh, I skipped over that. Still, though, the values probably default to 0. User#2 0 — 10y
0
I think so, any ways I tested it again, the board showed up, and then when I killed him it didn't count it onto the board, I think it may be the gun but it named the tag value the same thing. Any ideas? ultrabug 306 — 10y
0
I think the event is "Died" instead of "Dead" (of the Humanoid) User#2 0 — 10y
0
TY, that is it! ultrabug 306 — 10y
0
Nope, it is still not working. ultrabug 306 — 10y
0
Im going to repost what the script has now. ultrabug 306 — 10y
0
I edited my question with the new script. ultrabug 306 — 10y
0
I also edited my answer. User#2 0 — 10y
0
Okay and I start changing this up again. ultrabug 306 — 10y
0
level is parented to leaderstats right after kills. ultrabug 306 — 10y
0
Ahh, I couldn't find it. But the Died part still applies I assume User#2 0 — 10y
0
Probably, I saw the other way I had it with the loop in someone elses answer for finding the tag, so I figured I might aswell give it a shot. ultrabug 306 — 10y
0
I got the kills, xp, and level to work, but it only shows up for 1 person(the 1st person to join), the others don't even have 0s in their spots. ultrabug 306 — 10y
Ad

Answer this question