Still have questions? Join our Discord server and get real time help.
Log in to vote

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

Asked by 4 years ago

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
I believe that the 'break' function is only breaking the 'if' statement, not the repeat loop. RedCombee 580 — 4y

1 answer

Log in to vote
Answered by
Perci1 4905 Trusted Moderation Voter Community Moderator
4 years ago

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
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
game.Players.LocalPlayer.CameraMode = "LockFirstPerson"
game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson

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

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. TheeDeathCaster 2209 — 4y
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. Perci1 4905 — 4y

Answer this question