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

leaderstats Not a vaild member of player?

Asked by 7 years ago
Edited 7 years ago

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

Log in to vote
2
Answered by 7 years ago
Edited 7 years ago

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. :)

0
I found my own fix, All I did was added : game.Players.LocalPlayer:WaitForChild("leaderstats") theawesome624 100 — 7y
0
alright Warfaresh0t 414 — 7y
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Can you paste the leaderboard script?

0
when you test it out did you manually go into the character to check if they were in there? ZeonMaxwelll 75 — 7y

Answer this question