Loop acting weirdly

I have no idea how to explain it show ill just show a video and code :frowning:


Nevermind, I split the two loops and now it seems to work as intended

I lied, turns out its still acting the same way

why not just put the while loops out the function and rather have while true do
have while lightswitch.Toggled.Value == true do

Try adding a debounce to it.

local debounce
Event:Connect(function()
   if debounce then
      return
   end
   debounce = true
   -- Your code...
   -- ...
   
   -- At the end set debounce as false or nil
   debounce = false
end
1 Like

it has been a while since I’ve posted this, but this is an old project I’ve stopped working on but I have since figured how to stop something from happening in this and any future game I’ll work on and I’m hoping this post will help other in the future. here is some example code

 local death -- this defines the function as nil 
death = char:WaitForChild("Humanoid").Died:Connect(function() -- this will fire the function but also redfines it so it makes it easier for us to disconnect the function
	death:Disconnect() -- disconnects the function so that it won't fire more than once
end)

essentially you just have to make sure you disconnect the event once it fires to prevent it from firing multiple times

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