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?
1 | player = script.Parent.Parent.Parent.Parent |
2 | stats = player:WaitForChild( "leaderstats" ) |
3 | Level = stats:WaitForChild( "Level" ) |
4 |
5 | game.Players.PlayerAdded:connect( function () |
6 | if Level.Value > = 50 then |
7 | script.Parent.Visible = true |
8 | end |
9 | end ) |
1 | 1 : player = script.Parent.Parent.Parent.Parent |
2 | 2 : stats = player:WaitForChild( "leaderstats" ) |
3 | 3 : Level = stats:WaitForChild( "Level" ) |
4 | 4 : game.Players.PlayerAdded:connect( function () |
5 | 5 : if Level.Value = 50 then |
6 | 6 : script.Parent.Visible = true |
7 | 7 : end |
8 | 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
01 | local players = game:GetService( "Players" ) |
02 | local player = players.LocalPlayer |
03 | local stats = player:WaitForChild( "leaderstats" ) |
04 | local Level = stats:findFirstChild( "Level" ) |
05 |
06 | if not Level then print ( "Can't find level" ) return end |
07 | if Level.Value > = 50 then -- First check to see each time we respawn with the GUI |
08 | script.Parent.Visible = true |
09 | end |
10 |
11 | Level.Changed:connect( function () -- Every check after level changes |
12 | if Level.Value > = 50 and not script.Parent.Visible then |
13 | script.Parent.Visible = true |
14 | end |
15 | end ) |