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

I keep getting "leaderstats is not a valid member of Player" Please help me?

Asked by 5 years ago

So I had someone help me make a working leaderboard script where whenver a player dies in any way He/She will get 10 Tokens "Money" and +1 to the Death value.. But for some reason I am getting this problem where it says "leaderstats is not a valid member of Player" and the leaderboard does not work correctly as once it will add values and then when I test the game again it will not add any values at all and they would just stay at 0.. And that just keeps changing each time I test it. I would really appreciate it if someone could help me fix this please!

This is the script that adds the values for each time a player dies.

local players = game:GetService("Players")



players.PlayerAdded:Connect(function(plr)

local deaths = plr.leaderstats.Deaths

local tokens = plr.leaderstats.Tokens

plr.CharacterAdded:Connect(function(char)

char.Humanoid.Died:Connect(function()

deaths.Value = deaths.Value + 1

tokens.Value = tokens.Value + 10

end)

end)

end)
0
Is there a separate script that adds the leaderstats when they join? There has to be one. DeceptiveCaster 3761 — 5y
0
leaderstats is not a default roblox object, you gotta insert it first starmaq 1290 — 5y
0
Yes I have a script called "leaderboard" in ServerScriptService and in the leaderboard script I have the "Script" which I posted above, and I also have "leaderstats" in the leaderboard scripts with both values "Tokens" and "Deaths". diablotoken 6 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

leaderstats does NOT exist by default, you have to create a folder called leaderstats and add values (such as NumberValues) into this folder

local players = game:GetService("Players")



players.PlayerAdded:Connect(function(plr)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = plr

    local deaths = Instance.new("IntValue")
    deaths.Name = "Deaths"
    deaths.Parent = leaderstats

    local tokens = Instance.new("NumberValue")
    tokens.Name = "Tokens"
    tokens.Parent = leaderstats

    plr.CharacterAdded:Connect(function(char)

        char.Humanoid.Died:Connect(function()

            deaths.Value = deaths.Value + 1

            tokens.Value = tokens.Value + 10

        end)

    end)

end)
0
I have a folder called leaderstats and values "Deaths" and "Tokens". diablotoken 6 — 5y
0
maybe you are trying to access it before it is created, try using :WaitForChild fanofpixels 718 — 5y
0
So I have to remove :GetService and paste in :WaitForChild right? diablotoken 6 — 5y
0
No, definitely not. Just add the leaderstats like he is showing you. DeceptiveCaster 3761 — 5y
0
Thank you so much! This has worked! diablotoken 6 — 5y
Ad

Answer this question