How do I stop this function?

I want to know how to stop this function as it keeps going forever. I got this script from the Dev Forum on another topic that makes a GUI shake and I’m completely new to and don’t know anything about RunService. Can someone please help me and tell me how I can limit for how much time it runs for? Here’s the script.

2 Likes

There is connection for any functions you want to connect and disconnect, which means you can disconnect a function from the event that you have connected.

How do I do that exactly? As I said i’m completely new to this part of scripting.

Could you please send images and correctly format your code? Because your code is formatted via an image.

And speaking of correctly formatting the code, it’s like

DON’T COPY THE CODE!

--Code or whatever or the ridiculousness.

Sorry, I don’t know what you mean by that.

local RunService = game:GetService("RunService")
local Pos = script.Parent.Position

local connection = RunService.RenderStepped:Connect(function(dt)
      local BobbleX = (math.cos(os.clock()*2)*0.01)
      local BobbleY = math.abs(math.sin(os.clock() * 2))
      script.Parent.Position = Pos + UDim2.new(BobbleX,0,BobbleY,0)
      game.Workspace.Sound.SoundEffects.Gui.Notification:Play
end)
-- wait until something like a variable is set to true or a value is changed
connection:Disconnect()

edit: changed the variable to connection so it makes more sense

2 Likes

Yep, that’s how you can disconnect a function.

Thank you so much that really helps!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.