For some reason this simple script is not working and I have no idea why. What am I missing?
01 | local player = game.Players.LocalPlayer.leaderstats.Level.Value |
02 | repeat |
03 | wait( 10 ) |
04 |
05 |
06 | if player = = 1 then |
07 | wait( 0.1 ) |
08 | script.Parent.Text = "Private I (Lvl 1)" |
09 | elseif player = = 2 then |
10 | wait( 0.1 ) |
11 | script.Parent.Text = "Private II (Lvl 2)" |
12 | elseif player = = 3 then |
13 | wait( 0.1 ) |
14 | script.Parent.Text = "Private III (Lvl 3)" |
It is kinda ridiculous that this script works while LocalPlayer does not
1 | script.Parent.Parent.Parent.Parent.Parent.leaderstats.Level.Value |
Btw, this script is located at starterGUI
It's most likely due to the syntax of your script. A repeat
loop requires a while (condition)
at the end to specify what conditions are necessary for the repeat
loop to continue, and once that condition returns false, then the loop ends. Secondly, if else
statements require an end
at the end of the block. Here is a working version of your script:
01 | local player = game.Players.LocalPlayer.leaderstats.Level.Value |
02 |
03 | repeat |
04 | wait( 10 ) |
05 | if player = = 1 then |
06 | wait( 0.1 ) |
07 | script.Parent.Text = "Private I (Lvl 1)" |
08 | elseif player = = 2 then |
09 | wait( 0.1 ) |
10 | script.Parent.Text = "Private II (Lvl 2)" |
11 | elseif player = = 3 then |
12 | wait( 0.1 ) |
13 | script.Parent.Text = "Private III (Lvl 3)" |
14 | end -- Added this 'end' keyword |
15 | while (CONDITION) -- Added this statement |
I do not know what is your terminal condition is, which is why I wrote "CONDITION" where you should specify what you want it to be. If you are looking for this loop to continue infinitely, then I suggest replacing repeat
with while true do
and removing the last line. Furthermore, make sure that this is inside a LocalScript, and that the LocalScript is inside StarterGUI. Hope this helps.
There are 2 possible problems that I can see from reading this.
1)You haven't put it in a local script which will therefore make LocalPlayer not work. 2)You forgot to put the right amount of "end" on the end of the script.
This is because local player = game.Players.LocalPlayer.leaderstats.Level.Value
is saved as a number, not a property, so to fix this, define it as local player = game.Players.LocalPlayer.leaderstats.Level
and change player
in the if conditions to player.Value
.Also, apply WaitForChild
on this because the instances (Level, leaderstats) might have not loaded at the time of defining.