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

How can I make my script repeat itself forever?

workspace.CoreC.Temp.Value +=1

2 answers

✓ Accepted answer

Hey, you could use a while loop or a repeat loop for that :D

While Loop:

local CoreC = game.Workspace.CoreC.Temp -- Defines your part or whatever

while true do -- Will run forever
	
	CoreC.Value = CoreC.Value + 1 -- Set to how much the value is supposed to be
	wait(1) -- You want to have some cooldown or the game will crash
end

Repeat Loop:

repeat
	
	CoreC.Value = CoreC.Value + 1 -- Set to how much the value is supposed to be
	wait(1) -- You want to have some cooldown or the game will crash
	
until MyRepeater == false -- Basicaly runs forever untill MyRepeater is set to false

https://developer.roblox.com/en-us/articles/Loops

There are two ways: One is a while true loop. This one is only needed if you are adding in a wait in between each cycle. An example is if I want a countdown to go down every second. EXAMPLE:

local countdownTime = 60
local countdown = countdownTime
local inc = 1
while wait(inc) do --Every second this will run
	countdown -= inc --Setting the countdown variable to itself, but 1 less.
end

The second is a Run.Stepped function. This is only ran if you want it to run constantly every second. Using a wait() at the end won't work.

If you are on a server script, the only way to use it is like this:

local run = game:GetService("RunService")
run.Stepped:Connect(function()
	--do whatever here.
end)

But, if you are on a client (local) script, it can be used in two ways.

local run = game:GetService("RunService")
run.Stepped:Connect(function()
	--do whatever here.
end)
run.RenderStepped:Connect(function()
	--do whatever here
end)

The difference between Stepped and RenderStepped is that RenderStepped is better if you are, for example, making arms that follow your cursor client sided. If you use .Stepped, it'll lag out and glitch, but if you use .RenderStepped, it will look nice and smooth.

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