How to disable a remote event?

I’ve created this remote event for a knockback script but I was wondering, how do I disable a remote event 2 seconds after it’s been fired?

2 Likes

Just simply disconnect the connected function to disable it completely.

local connection

connection = RemoteEvent.OnServerEvent:Connect(function()
--do stuff
wait(2)
connection:Disconnect()
end)

For a debounce script do:

local Debounce = true

RemoteEvent.OnServerEvent:Connect(function()
if Debounce then
Debounce = false
--do stuff
wait(2)
Debounce = true
end
end)
3 Likes

You would need to create a debuff.
Before the event you will need to create a variable e.g REDebuff
at the start of your event you will check if the dubuff is active so:
if REDebuff == true then
*Dont Run
else
REDebuff = true
*run the code
wait(Time)
REDebuff = false

so when it starts to run it will make the debuff activate making any aditional events not do anything

1 Like

If you mean the knock back, simply use game.Debris:AddItem(stuff, stuff)

If you mean the remote to finish, that will happen automatically.

If you mean the remote to prevent it from executing, you have to disable the server script used to connect the event to the remote.

1 Like

sorry but it didn’t work :frowning_face:

Thats because the coding was incorrect. Its along the right lines but should look more like this:

local Debuff = false

RE.OnServerEvent:Connect(function()
if Debuff == false then
  Debuff = true
-- Do the roar
  wait(2)
  Defuff = false

else
-- NO DONKEY
end
end)
3 Likes

Whoops that’s because I never set Debounce to true. You need to set that to true before anything

@minimic2002 is right - although you don’t need to put an else if you’re disabling it

(I also prefer the cleaner way of just checking if debounce is true and doing it instead of checking if it’s false but that’s personal preference)

1 Like