Server side Remote Event firing more than Once

There’s a similar topic out there with a similar problem to mine. It’s resolved but the answer doesn’t fix the problem. This link: Remote Event being received too many times

I have a GUI button on client side that fires a remote event at the server which after a certain time the server fires back at the client to update its values to match the server. The only problem is that the server is firing to the client more than once if I spam the GUI button.

--Server Side
local debounce = {}
local function runTime(player,ins)
	if debounce[tostring(ins)] == nil then
		debounce[tostring(ins)] = true
    print("Client has called") --fires 1x
    wait(3)
	RunTime:FireClient(player) --fires 3-5x in succession
		debounce[tostring(ins)] = nil
	else
		return nil
	end
end

--Client Side
lem.bt.MouseButton1Click:Connect(function()
	Request:FireServer("Lemon") --fires at server
	animations(lem,SavedData.Lemon[3]):iInput() --animation plays to fill time..
	RunTime.OnClientEvent:Connect(function(boolean) --fires 3-5x
		print("Opening Call with Server..")--prints 3-5x
	end)
end)

Edit: This awfully reminds of the “Two Generals Problem”.

2 Likes

I found out the problem however for anybody that runs into this same problem.

Do not put OnClientEvent inside another event like I did…

local Request = ReplicatedStorage:WaitForChild("Request")
lem.bt.MouseButton1Click:Connect(function() --gui button press
      Request:FireServer() --client(you) -> server -> client(you)
      Request.OnClientEvent:Connect(function() -- where the problem begins.
    end)
end)

Make sure to keep it seperate into a block of itself inside the script not inside a different event block.

4 Likes

Use Remote Functions, Because they do the job that you want to achieve.
Plus Add a debounce to the button event. Sometimes even if you click once, the event will be triggered twice.
Thats why.
_(O.O)_/

Well theres a problem I read about Remote Functions which is why I’m using Remote Event and avoiding Remote Function.

If the Remote Function throws an error the server throws an error, that means it also could throw errors for other clients. I’m not quite sure if this is accurate but I read it on Developer.