Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is LocalPlayer not viable anymore?

For some reason this simple script is not working and I have no idea why. What am I missing?

local player = game.Players.LocalPlayer.leaderstats.Level.Value
repeat 
wait(10)


if player == 1 then
wait(0.1)
script.Parent.Text = "Private I (Lvl 1)"
elseif player == 2 then
wait(0.1)
script.Parent.Text = "Private II (Lvl 2)"
elseif player == 3 then
wait(0.1)
script.Parent.Text = "Private III (Lvl 3)"

It is kinda ridiculous that this script works while LocalPlayer does not

script.Parent.Parent.Parent.Parent.Parent.leaderstats.Level.Value

Btw, this script is located at starterGUI

3 comments

0

Local Player only works in a Local Script

0

I am able to use game.Players.LocalPlayer in other script so it does work. Its just this one won't work

0

why is there a repeat at the top, and if its on purpose where is end and until?

3 answers

✓ Accepted answer

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:

local player = game.Players.LocalPlayer.leaderstats.Level.Value

repeat 
	wait(10)
	if player == 1 then
		wait(0.1)
		script.Parent.Text = "Private I (Lvl 1)"
	elseif player == 2 then
		wait(0.1)
		script.Parent.Text = "Private II (Lvl 2)"
	elseif player == 3 then
		wait(0.1)
		script.Parent.Text = "Private III (Lvl 3)"
	end -- Added this 'end' keyword
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.

1 comment

0

You forgot the end at the end as well

This discussion is preserved as it was. New answers, comments, and votes are closed.