Easiest way to stop RenderStepped?

I wan’t renderstepped to constantly make something bigger and redder when a specific song is played until that song ends.

I know you can disconnect it by storing the process in a variable and attatching :Disconnect() after but I am unsure how to make the condition for the disconnect such that I don’t have to put the condiction in an ever-lasting loop, thus making it pointless because i’ll stiill have an infinite loop.

I tried disconnecting it from inside itself but the variable isnt in the right scope.

local RS = game:GetService("ReplicatedStorage")
local WS = game:GetService("Workspace")
local RunS = game:GetService("RunService")

local audio = RS.startrekything
local event = RS.End

event.Event:Connect(function(player) --this fires if the easter-egg music is played by chance by someone
	print("hi",player)
	if player == game.Players.LocalPlayer then
		RunS.RenderStepped:Connect(function() --this should terminate then timePosition >= TimeLength so i can make the object shrink turn blue and go boom 
				local length = audio.TimeLength+2
				local t = audio.TimePosition+2
				WS.corona.Size = Vector3.new(.21*t,.21*t,.21*t)
				WS.sun.Size = Vector3.new(.2*t,.2*t,.2*t)
				WS.corona.Color = Color3.fromRGB(255,176-(176*t/length),0)
				WS.sun.Color = Color3.fromRGB(255,255-(255*t/length),150-(150*t/length))
		end)
	end
end)

script.Parent.FocusLost:Connect(function()
	audio.SoundId = "rbxassetid://"..script.Parent.Text
	if script.Parent.Text == "5229146943" then
		RS.End:Fire(game.Players.LocalPlayer)
	end
	audio.TimePosition = 0
end)
2 Likes

Using a different method

RunService:BindToRenderStep('name', Enum.RenderPriority.Last, function() end) 
-- basically the same as .RenderStepped


RunService:UnbindFromRenderStep('name')
-- unbinds the function from being fired

You could do something like

local connection
connection = RunS.RenderStepped:Connect(function()
    connection:Disconnect()
end)
5 Likes

You can use a while loop and then break it.

1 Like

or you could use a ratio and break it

8 Likes

Make a variable like “local blah = false”, then right below the RunService do:
if blah == false then
– stuff here
blah = true
end

I wouldn’t suggest doing it this way and using like BindToRenderStep or something.

the best way in my opinion is probably this:

local conn

script.Parent.FocusLost:Connect(function()
	audio.SoundId = "rbxassetid://"..script.Parent.Text
	if script.Parent.Text == "5229146943" then
		if conn then conn:Disconnect() end
		conn = RunS.RenderStepped:Connect(function(dt) --this should terminate then timePosition >= TimeLength so i can make the object shrink turn blue and go boom 
				local length = audio.TimeLength + ((1/30)*dt)
				local t = audio.TimePosition + ((1/30)*dt)
				WS.corona.Size = Vector3.new(.21*t,.21*t,.21*t)
				WS.sun.Size = Vector3.new(.2*t,.2*t,.2*t)
				WS.corona.Color = Color3.fromRGB(255,176-(176*t/length),0)
				WS.sun.Color = Color3.fromRGB(255,255-(255*t/length),150-(150*t/length))
			if length / timePosition >= 1 then
				conn:Disconnect()
			end
		end)
	end
	audio.TimePosition = 0
end)
11 Likes

This is a W ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ

1 Like

common for me i fear …

.

5 Likes