Debounce Issue with Remote

Hello,

I’m trying to make a Local Script Fire a Server when you mouse click for a tool, that sends off a remote to make the action serverside.

The issue I’m dealing with is that my debounce doesn’t function and during the wait period you can still fire the server for some unknown reason.

I’ve tried to make it one time use only to pinpoint the issue but it fires server even if the Injectable is set to false.

22

Edit:

local Injectable = true

Gun.Activated:Connect(function()
	if Injectable == true then
		Injectable = false
		script.Parent.Events.Script.RemoteEvent:FireServer()
		wait(5)
		Injectable = true
	else
		Empty:Play()
	end
end)

The FireServer() code should be after Injectable is set to false! Also, you are not returning Injectable to its original true state.

You never set Injectable to true after you set it to false so the code below the condition will run only once if it’s ever evaluated, set it to true like this:

oie_sUNj8A8j7O4Y
^ right before the end)

Also move the wait(5) to right before setting Injectable to true as well, unless you only want that wait if the first condition returns true.

Ok so, I can’t still get it to work, I’ll go into some more detail…

The script it executes print("Injecting)… and does the healing function…

During the 5 second cooldown it still heals if you press even though it plays the empty sound.

so the debonce didn’t work…

2z

I meant put the yield right before setting it to true, and set it to true right before the final end) as the image depicted

I also suggest pasting preformatted code on the forum so it’s easier to alter it.

Edit:

local Injectable = true

Gun.Activated:Connect(function()
	if Injectable then -- don't need to explicitly compare to check whether its true, this basically is the same thing but looks neater
		Injectable = false
		script.Parent.Events.Script.RemoteEvent:FireServer()
	else
		Empty:Play()
	end
		wait(5)
		Injectable = true
end)

I’ve added the code for your reference

Nevermind, I’ve figured out the issue was I had the healing effect not included in the remote script, but in a separate script not affected by the local script. It was a silly thing to miss…

Solved :crazy_face:

1 Like