I'm trying to make a script that makes a gui appear only if a player has surpassed a certain leaderstat, this is the code I have so far and there's nothing wrong with the Parents or anything like that so I can't find my error, any help?
player = script.Parent.Parent.Parent.Parent stats = player:WaitForChild("leaderstats") Level = stats:WaitForChild("Level") game.Players.PlayerAdded:connect(function() if Level.Value >= 50 then script.Parent.Visible = true end end)
1: player = script.Parent.Parent.Parent.Parent 2: stats = player:WaitForChild("leaderstats") 3: Level = stats:WaitForChild("Level") 4: game.Players.PlayerAdded:connect(function() 5: if Level.Value = 50 then 6: script.Parent.Visible = true 7: end 8: end)
You messed up and wrote a > which messes up the script
You're trying to index player and are also using PlayerAdded. That tells me you're trying to use this in a LocalScript in PlayerGui. You can't use PlayerAdded in this way. You can use ChildAdded, but either way, what you seem to be doing isn't going to work.
This needs to be in a LocalScript
local players = game:GetService("Players") local player = players.LocalPlayer local stats = player:WaitForChild("leaderstats") local Level = stats:findFirstChild("Level") if not Level then print("Can't find level") return end if Level.Value >= 50 then -- First check to see each time we respawn with the GUI script.Parent.Visible = true end Level.Changed:connect(function() -- Every check after level changes if Level.Value >= 50 and not script.Parent.Visible then script.Parent.Visible = true end end)