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.
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)
When you are searching for leaderstats it is still being created.
I think using player:WaitForChild("leaderstats",2).Points.Value
might be appropriate here
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
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!
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 :)