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

leaderstats Not a vaild member of player?

So I expected this script :

humanoid = game.Players.LocalPlayer.Character.Humanoid
level = game.Players.LocalPlayer.leaderstats.Level

humanoid.MaxHealth = 100 + (level * 2)

to set my health to 102 (because my level is 1) but it gives me this error : leaderstats is not a valid member of Player What's wrong? leaderstats script

local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	local level1 = Instance.new("IntValue")
	level1.Name = "Level"
	level1.Value = level:GetAsync(key)
	level1.Parent = leaderstats
	local gold1 = Instance.new("IntValue")
	gold1.Name = "Gold"
	gold1.Value = gold:GetAsync(key)
	gold1.Parent = leaderstats

That isn't the whole thing, but I think that'll help out

2 answers

You have 2 errors in your script (possibly a third). 1. You didn't properly create the leaderstats "folder" and you were trying to multiply a userdata value.

Fix

For the leaderboard on Line 1 you create a folder to hold your leaderstats, you need to change that to an IntValue. Also, you haven't put in a PlayerAdded function to create the leaderboard. (Not sure if that's the thing you removed like you said.)

Now, for your other script that changes the max health. On Line 2 you forgot to put a .Value, so on Line 4 you are trying to multiply the word "Level".

Final Scripts:

The health script:

humanoid = game.Players.LocalPlayer.Character.Humanoid
level = game.Players.LocalPlayer.leaderstats.Level.Value

humanoid.MaxHealth = 100 + (level * 2)

The leaderboard script:

function onPlayerAdded(player)
local leaderstats = Instance.new("IntValue")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player
    local level1 = Instance.new("IntValue")
    level1.Name = "Level"
    level1.Value = level:GetAsync(key)
    level1.Parent = leaderstats
    local gold1 = Instance.new("IntValue")
    gold1.Name = "Gold"
    gold1.Value = 0
    gold1.Parent = leaderstats
end

game.Players.PlayerAdded:connect(onPlayerAdded)

If you thought this was helpful make sure to up vote and accept this answer. :)

2 comments

0

I found my own fix, All I did was added : game.Players.LocalPlayer:WaitForChild("leaderstats")

0

alright

Can you paste the leaderboard script?

1 comment

0

when you test it out did you manually go into the character to check if they were in there?

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