Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

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

1 answer

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 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
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.

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. TheeDeathCaster 2368 — 9y
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. Perci1 4988 — 9y
Ad

Answer this question