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

How to prevent a loop from lagging my game?

Asked by 3 years ago

Legit I have to make my question title complicated to get this through.

I was wondering on how to make a non-laggy loop.

while true do
    wait(.01)
    game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic
end

Doing this, I feel like it lags my game making spawn delays (I'm not 100% sure on that). I wonder if what I made is correct and if there's another way to loop without lag.

2 answers

Log in to vote
1
Answered by 3 years ago

One thing that you could do is this:

while wait(0.01) do
    game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic
end

The problem with this script is that you don't need to be constantly setting the CameraMode. If you put this LocalScript in StarterPlayerScripts with this single line, it'll have the same effect.

game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic
0
but what's the different when you do while wait () do TheBuliderMC 84 — 3y
0
There's no difference in how the code executes but it looks a lot cleaner RedneckBane 100 — 3y
Ad
Log in to vote
-1
Answered by 3 years ago
Edited 3 years ago

Another thing that you can do is just a simply wait .5

while true do -- Sets the loop to constantly run.
    wait(.5) -- Waits .5
    game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic -- Enables the camera to classic!
end

Even though the camera mode in Roblox Studio is already classic, you can make sure that you set it to that by going in through StarterPlayer and clicking it to Classic.

The while true do and wait(.5) are not needed because when you set the mode of a camera you're locking it to that mode.

game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic -- Enables the camera to classic without having to put in the while true do loop!

This should work, hope this helped!

Extra Help

Here ya go

0
Why did this get downvoted it works. Nicholas1088 169 — 3y

Answer this question