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

How to prevent a loop from lagging my game?

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

✓ Accepted answer

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

2 comments

0

but what's the different when you do while wait () do

0

There's no difference in how the code executes but it looks a lot cleaner

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

1 comment

0

Why did this get downvoted it works.

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