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)
RunService:BindToRenderStep('name', Enum.RenderPriority.Last, function() end)
-- basically the same as .RenderStepped
RunService:UnbindFromRenderStep('name')
-- unbinds the function from being fired
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)