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

"leaderstats is not a valid member of player" But it is?

Apparently leaderstats is not in the player when this script runs. I added a WaitForChild but that doesn't seem to help at all. Any ideas?

lead = game.Players.LocalPlayer.leaderstats

local Leaderboard = game.Players.LocalPlayer:WaitForChild("leaderstats")

Leaderboard.RankVal.Changed:connect(function(value)
	if value == 1 then lead.Rank.Value = "Newbie" elseif
		value == 2 then lead.Rank.Value = "Member" elseif
		value == 3 then lead.Rank.Value = "Forager" elseif
		value == 4 then lead.Rank.Value = "Watcher" elseif
		value == 5 then lead.Rank.Value = "Night Watcher" elseif
		value == 6 then lead.Rank.Value = "Warrior" elseif
		value == 7 then lead.Rank.Value = "Runner" elseif
		value == 8 then lead.Rank.Value = "Elder"
end
end)
print("Leaderboard is running.")

function onPlayerEntered(newPlayer)
    wait(.5)
    local stats = Instance.new("StringValue")
    stats.Name = "leaderstats"
    local stats2 = Instance.new("StringValue")
    stats2.Name = "Tycoon"

    local cash = Instance.new("IntValue")

    cash.Name = "" 
	cash.Value = nil
	
	local val = Instance.new("IntValue")
	val.Name = "RankVal"
	val.Value = 1

--check if the player owns your gamepass
    if game:GetService("MarketplaceService"):PlayerOwnsAsset(newPlayer, 384198804) then
    cash.Value = 10 -- change cash to 500,000 (can't have a comma)
	else
	cash.Value = 1
    end
    cash.Parent = stats
    stats2.Parent = newPlayer   
    stats.Parent = newPlayer
end
game.Players.ChildAdded:connect(onPlayerEntered)

3 comments

0

Take out the first line

0

Okay now I'm getting another error. It's telling me that RankVal does not exist. How can this be if I create it? I check in a studio test and it does not create itself within the player.

0

I'll post an asnwer

1 answer

✓ Accepted answer

For the first script, remove the first line, since you already set a WaitForChild after it. The reason you're getting the error that 'RankVal' doesn't exist, is because it's not located in 'leaderstats'. In your second script, line 26, you parented 'stats2', representing 'RankVal', to the player! Instead, it should be parented to 'stats', which represents leaderstats. I recommend switching 26 with 27, and vice versa, then changing the NEW line 27 to 'stats2.Parent = stats'. In case I was confusing:

print("Leaderboard is running.")

function onPlayerEntered(newPlayer)
    wait(.5)
    local stats = Instance.new("StringValue")
    stats.Name = "leaderstats"
    local stats2 = Instance.new("StringValue")
    stats2.Name = "Tycoon"

    local cash = Instance.new("IntValue")

    cash.Name = "" 
    cash.Value = nil

    local val = Instance.new("IntValue")
    val.Name = "RankVal"
    val.Value = 1

--check if the player owns your gamepass
    if game:GetService("MarketplaceService"):PlayerOwnsAsset(newPlayer, 384198804) then
    cash.Value = 10 -- change cash to 500,000 (can't have a comma)
    else
    cash.Value = 1
    end
    cash.Parent = stats
    stats.Parent = newPlayer   
    stats2.Parent = stats
end
game.Players.ChildAdded:connect(onPlayerEntered)

2 comments

0

Thanks for the help, Shawnyg.

0

No problem. I just noticed you could've kept stats2 on the same line :p. Oh well

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