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

Why is my 'FirstPerson' code repeating over and over?

I have done a few changes, but it keeps repeat the code over and over again without stopping, I have changed the code to stop, but it does not stop, and there is no Output, here is the script;

repeat wait() until game.Players.LocalPlayer
local plr = game.Players.LocalPlayer
repeat wait() until plr.Character

repeat plr.CameraMode = 0 wait(.1) plr.CameraMode = 1 wait(.1) if plr.CameraMode == 1 then break end until plr.CameraMode == 1

1 comment

0

I believe that the 'break' function is only breaking the 'if' statement, not the repeat loop.

1 answer

✓ Accepted answer

Line 1 is unnecessary, LocalPlayer will always exist.

I also don't see the point of a repeat loop since you're essentially doing;

--You set the camera mode to 0, then set it to 1, but you end the loop when the camera mode equals 1, thus you're doing:
plr.CameraMode = 0
wait(0.1)
plr.CameraMode = 1

Why you would want to set it to normal, then LockFirstPerson one tenth of a second later, I have no idea. It seems rather pointless. It you just want to set the camera to LockFirstPerson, any of these three pieces of code will suffice:

game.Players.LocalPlayer.CameraMode = 1
--Or,
game.Players.LocalPlayer.CameraMode = "LockFirstPerson"
--Or,
game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson

If you wanted to do something other than this, please say so.

2 comments

0

Thanks man! It solved my problem! ;D By the way, why did it keep repeating before? I'm just wondering because I even added a 'break' method to even try and stop it. o_e Also, I set it to normal before doing FirstPerson because, if I reset, it'll revert back to Classic mode for some reason.

0

Not entirely sure why it would keep looping, although it is a bad - and pointless - idea to put a break in a repeat loop, just use the until part of it! Setting it to normal is still pointless because a local script in StarterGui will run each time the player respawns, thus setting it to LockFirstPerson each time they respawn.

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