RemoteEvents recieved twice after being fired once

i’m currently making a fast-paced tag game on roblox, but i’ve realized that when the remoteevent is recieved on the client, it fires twice. i’ve tried a debounce, which for some reason didnt work.

this is my function that fires the event from the server to all clients:

local function send(…)
events.serverInput:FireAllClients(…)
end

this is my reciever on the client:

events.serverInput.OnClientEvent:Connect(function(character, action, originPos, endPos, distance)
if inputDebounce then return end
inputDebounce = true

print("fired")

if action == "dash" then
	trail(character, 10, 0.03, 0.3, 0.6, character:WaitForChild("Body Colors").TorsoColor3)
elseif action == "doublejump" then
	trail(character, 4, 0.05, 0.3, 0.6, character:WaitForChild("Body Colors").TorsoColor3)
elseif action == "dive" then
	lightningvfx(character, originPos, endPos, distance)
end

wait(0.5)
inputDebounce = false

end)

the weirdest part about all of this is that the issue only happens on some servers, which has led me to believe it might be an issue with roblox itself. the only posts i’ve found on it have said to add a debounce, and i’ve tried with numerous cooldowns. the shortest cooldown i can do without messing up the vfx is 1 (due to the game being fast-paced), and it still fires twice with cooldowns greater than 1 for some reason.

should i just try a different approach to handling the inputs, such as adding vfx on the client and trying to sync it to the server without a remoteevent? if so, i want to know if the wait() function will delay scripts for the same amount of time without interference from client and server speeds.

notes for context:

  • the reciever is not nested in anything
  • i’ve checked the send function with prints and it fires once

My 1st guess would be wait(0.5) is too fast.

that’s what i thought too, but i’ve tried it with greater cooldowns. i noticed that if the debounce was false, it would still fire twice. if the debounce was true, it wouldn’t fire at all.

2nd guess some other script is involved.

i doubt it’s another script, as this is the only script that recieves this remoteevent, and the function i mentioned that fires the event is only found and used in one server script.

try using search and find method to see for connected event. there is also a possibility that the script clones itself causing the connection to double, to check that do

print("Connecting Event")
events.serverInput.OnClientEvent --so on

i tried this, and the “connecting event” print fired once. i’m not sure if this is a scripting error or a bug, as i’ve found numerous other posts with the same problem but no solution other than using a debounce, which didnt work here.

I just noticed you have the debounce after
events.serverInput.OnClientEvent:Connect
The debounce should be after the input trigger.
This should work too. so the error may not be here

i tried to move inputDebounce = true to after the input trigger, but it didn’t work. if you mean the definition, inputDebounce is defined before the reciever.

theres also still no explanation to why this issue only happens on some servers and not others.

Do the entire debounce on the Tigger side. You are getting one to work on the :Connect() but the trigger side is still sending 1300 requests.

It may have something to do with FireAllClients().

Hard to say without seeing how all this is working.

the server-side already only fires the event once

i’d normally include both full scripts, but what confuses me the most is that it’s not consistent through all servers. the only thing that should matter is that the send function fires once (confirmed by a print), but the client-side is receiving the event twice, while there is no other script that triggers the event. even if there was, there is no explanation for why the issue would happen on different servers unless some random chance was involved. it’s all very confusing.

i’m going to try this, and if it works well enough i’ll mark it as a solution. in the meantime, if someone figures out why this happens, let me know.

Something is wrong someplace. It’s not a glitch in Roblox. So yes I would step back take a long look at things and try a different approach. It looks like you have that debounce set up right. Myself I really don’t like doing it that way and stick to …

db=true -- as a value set long before it hits the point it's used.

if db then db=false
  --
  --
  task.wait(2) -- whatever works
  db=true
end

Good Luck

i noticed something else while i was trying to figure out another way to do this:

image

the second print of “fired” does not have anything saying it’s the client, and i’m not sure if that’s normal or not.

i figured out this happened because the reciever’s script was in startercharacterscripts. good to know for the future.

2 Likes

Same thing happens when receiver server script is in Workspace.

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