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

Why does studio say that leaderstats is not a member of player?

Asked by 3 years ago

I made this leaderboard script:

game.Players.PlayerAdded:Connect(function(player)

    local leaderstats = Instance.new("Folder") 
    leaderstats.Name = "leaderstats"


    local Points = Instance.new("IntValue")
    Points.Name = "Points"

    end)

the script works well but im trying to make it so that when someone has 5 points a door opens but it gives me an error saying that leaderstats is not a valid member of player, this is the script for the door:

game.Players.PlayerAdded:Connect(function(player)
    if player.leaderstats.Points.Value == 5 then
        script.Parent.Transparency = 0.5
        script.Parent.CanCollide = false
    end
    end)

i've tried a lot of stuff and asked my friends but we haven't been able to figure it out why it gives me that error.

5 answers

Log in to vote
0
Answered by 3 years ago

Bcs it happens the same moment the leaderstats are created so it will not work. I got an idea to help you! Try this:

    game.Players.PlayerAdded:Connect(function(player)
wait(2)
        if player.leaderstats.Points.Value == 5 then
            script.Parent.Transparency = 0.5
            script.Parent.CanCollide = false
        end
    end)

So it will wait 2 second (enough to create the leaderstats) See its not that hard(please make this an answering answer)

Ad
Log in to vote
0
Answered by 3 years ago

When you are searching for leaderstats it is still being created.

I think using player:WaitForChild("leaderstats",2).Points.Value might be appropriate here

Log in to vote
0
Answered by
JesseSong 3916 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

Problem:

I believe your script was checking through the leaderstats to find "Points" value. Since the leaderstats was trying to find a value; which doesn't exist it resulted in an error. You also didn't parent the intvalue's to the parent which is why it didn't work.


game:GetService("Players").PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder",player) leaderstats.Name = "leaderstats" local Points = Instance.new("IntValue",leaderstats) Points.Name = "Points" local part = workspace.Part if tostring(Points.Value >=0) then part.Transparency = 0.5 part.CanCollide = false print("It works!") else end end)

Solution:

Make sure you use tostring; as it has practical uses, especially when making GUI's!

References:

Learn how to make a leaderstat door

How to make a leaderstats door!

Note: If you want it to check constantly, add a wait!

Cheers! JesseSong

0
bruh do not think it will work he is trying to make a "leaderstats" ninjabluekris -4 — 3y
0
What are you talking about? JesseSong 3916 — 3y
Log in to vote
0
Answered by
iactz 15
3 years ago

I'm not exactly sure what your post is about since im pretty stupid, but I believe your door isn't working since you aren't putting the leaderstats in the player? [In your post at least]. You did:

local leaderstats = Instance.new("Folder") 
leaderstats.Name = "leaderstats"

local Points = Instance.new("IntValue")
Points.Name = "Points"

but you never set the parent of the thing you were creating, so it should be:

local leaderstats = Instance.new("Folder",player) 
leaderstats.Name = "leaderstats"

local Points = Instance.new("IntValue",player)
Points.Name = "Points"

If that still doesn't work, just put a

wait(1)

at the top of your door script

Hope you figure it out!

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

So what you did worng was that you forgot to put the leaderstats folder to player. So add this script "leaderstats.Parent = player" this will put leaderstarts to the player" and after put "Points.Parent = leaderstats" this will put "point" IntValue into the folder and after do "points.Value = 0" so when a player joins he/she gets 0 points :)

Script:

game.Players.PlayerAdded:Connect(function(player)

 local leaderstats = Instance.new("Folder")
 leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local Points = Instance.new("IntValue")
Points.Name = "Points"
Points.Value = 0
Points.Parent = leaderstats

        end)

and for the door sciript so when you do "while wait()do it will refresh the script everytime so when a player touches so then the door will open :

game.Players.PlayerAdded:Connect(function(player)
    while wait() do 
    if player.leaderstats.Points.Value == 5 then
        script.Parent.Transparency = 0.5
        script.Parent.CanCollide = false
    end
    end
    end)

Hope it helped :)

Answer this question