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 4 years ago

I made this leaderboard script:

01game.Players.PlayerAdded:Connect(function(player)
02 
03    local leaderstats = Instance.new("Folder")
04    leaderstats.Name = "leaderstats"
05 
06 
07    local Points = Instance.new("IntValue")
08    Points.Name = "Points"
09 
10    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:

1game.Players.PlayerAdded:Connect(function(player)
2    if player.leaderstats.Points.Value == 5 then
3        script.Parent.Transparency = 0.5
4        script.Parent.CanCollide = false
5    end
6    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 4 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:

1    game.Players.PlayerAdded:Connect(function(player)
2wait(2)
3        if player.leaderstats.Points.Value == 5 then
4            script.Parent.Transparency = 0.5
5            script.Parent.CanCollide = false
6        end
7    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 4 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
4 years ago
Edited 4 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.

01game:GetService("Players").PlayerAdded:Connect(function(player)
02 
03    local leaderstats = Instance.new("Folder",player)
04    leaderstats.Name = "leaderstats"
05 
06 
07    local Points = Instance.new("IntValue",leaderstats)
08    Points.Name = "Points"
09    local part = workspace.Part
10 
11           if tostring(Points.Value >=0) then
12           part.Transparency = 0.5
13           part.CanCollide = false
14        print("It works!")
15        else
16        end
17    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 — 4y
0
What are you talking about? JesseSong 3916 — 4y
Log in to vote
0
Answered by
iactz 15
4 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:

1local leaderstats = Instance.new("Folder")
2leaderstats.Name = "leaderstats"
3 
4local Points = Instance.new("IntValue")
5Points.Name = "Points"

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

1local leaderstats = Instance.new("Folder",player)
2leaderstats.Name = "leaderstats"
3 
4local Points = Instance.new("IntValue",player)
5Points.Name = "Points"

If that still doesn't work, just put a

1wait(1)

at the top of your door script

Hope you figure it out!

Log in to vote
0
Answered by 4 years ago
Edited 4 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:

01game.Players.PlayerAdded:Connect(function(player)
02 
03 local leaderstats = Instance.new("Folder")
04 leaderstats.Name = "leaderstats"
05leaderstats.Parent = player
06 
07local Points = Instance.new("IntValue")
08Points.Name = "Points"
09Points.Value = 0
10Points.Parent = leaderstats
11 
12        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 :

1game.Players.PlayerAdded:Connect(function(player)
2    while wait() do
3    if player.leaderstats.Points.Value == 5 then
4        script.Parent.Transparency = 0.5
5        script.Parent.CanCollide = false
6    end
7    end
8    end)

Hope it helped :)

Answer this question