Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

3 comments

0

Is there a separate script that adds the leaderstats when they join? There has to be one.

0

leaderstats is not a default roblox object, you gotta insert it first

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".

1 answer

✓ Accepted answer

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)

5 comments

0

I have a folder called leaderstats and values "Deaths" and "Tokens".

0

maybe you are trying to access it before it is created, try using :WaitForChild

0

So I have to remove :GetService and paste in :WaitForChild right?

0

No, definitely not. Just add the leaderstats like he is showing you.

0

Thank you so much! This has worked!

This discussion is preserved as it was. New answers, comments, and votes are closed.