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

How can I stop a RenderStepped loop from running?

I'm working on a door transition script that fads a black gui using renderstepped, but it has to fire an event afterwards to teleport a player, but I don't want it to keep doing that.

local doorTransition = game.ReplicatedStorage.Remote.ServerToClient.Event.DoorTransition

doorTransition.OnClientEvent:Connect(function(plr)
	
	print("Recieved from server")
	
	--////Fancy transitioning
	local runService = game:GetService("RunService")
	
	runService.RenderStepped:Connect(function()
		

		script.Parent.BackgroundTransparency = script.Parent.BackgroundTransparency - 0.025
		
		if script.Parent.BackgroundTransparency <= 0 then
			

			
		end
		
		
	end)
	
end)

2 answers

It would be best to use what Roblox provides you with. BindToRenderStep and UnbindFromRenderStep.

local runServ = game:GetService("RunService")

runServ:BindToRenderStep("test", Enum.RenderPriority.Camera.Value, function() print("ran") end)

wait(2)

runServ:UnbindFromRenderStep("test")

Hope this helps.

Example from Locard:

local runService = game:GetService('RunService')
local Stepped
Stepped = runService.Stepped:Connect(function()
    print('Printing')
end)

wait(.5)
Stepped:Disconnect()

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