RemoteEvent being fired multiple times when it is only supposed to be fired once

Hello all, I currently have an issue. My issue is that I am working on an admin commands system and I when I run a command which is supposed to fire a remoteevent. It successfully fires the event and does the action, but it for some reason fires multiple times. An example can be shown below, where I run a “pm” (private message) command and it shows multiple message boxes when it supposed to show only 1.

https://gyazo.com/b6bdf9dd5fea130153db7403b61c575e

Any help is appreciated!

6 Likes

This isa pretty common issue with data stores. I think one of the solutions was to add a cooldown on the server side, so that only 1 can be fired within X time

2 Likes

Yes, we can definitely help you because you provided all the code so we can see what’s wrong!

I’ll attach some screenshots of my code tommorow when i have access to my pc.

This happends quite a lot with RemoteEvents. Consider adding a Debounce.

local Debounce = false

Remote.OnClientEvent:Connect(function() 
    if Debounce then return end -- if the debounce is true, then return because the event was already fired and is currently running code
    Debounce = true -- if the debounce wasn't true, set it to true now since we are running code for the event

    -- run whatever code you want for the gui blah blah blah 

    task.wait(1) -- wait 1 second
    Debounce = false -- then set the debounce to false so we can receive more firings from the remote event
end)

See more helpful information about Debounce, here: Debounce – When and Why (roblox.com)

2 Likes

The problem is with the server script firing the event multiple times, cooldown is probably the most dumb way of fixing it.

1 Like

What would you suggest? I don’t see why debounce is a bad idea for this situation

No, a cooldown is a highly effective way of fixing it. The first instance fires, sets the debounce to true (preventing the future attempts from firing), then waits a set period of time before “unlocking” it again.

What is your problem with it?

1 Like

I’d suggest fixing the actual issue instead of looking for a workaround.

1 Like

The problem is that you should focus on fixing the actual issue instead of looking for any workaround just to make it work…

That is false.

That is pretty common for me. So sometimes I would add a debounce to prevent this from happening.

This is not false.
You use debounce when you’re aware that some actions may occur too frequently under certain circumstances and you want to set a minimum delay between the actions.

In this case, there’s a bug with the server script that needs to be fixed.
If you use debounce in such cases, it means you’re usually not aware of what’s going on in your scripts.

1 Like

And that is literally the problem the OP is facing.

So? At least it still managed to fix the problem the OP is facing. Sure, you can go ahead and spend hours trying to find that one bug that you might not even able to find when you have checked your code multiple times, but in the end you won’t be able to find those issues because Roblox Studio itself is unstable. The best way to play test something is to just play it as a published Roblox game.

2 Likes

Well, I don’t spend hours on fixing a simple bug.
Saying that it’s so hard to fix your code because of the Roblox Studio being unstable is simply ridiculous.

1 Like

Up to you if you want to believe it, but I’ll tell my story first.

Recently, I used the PlayerAdded event in Roblox Studio. At first, the event fired every time I play test in studio, however for some unknown reasons, it stopped firing in studio, rather that it only fired when I play in an actual Roblox published game.

The same goes to PlayerRemoving, for odd reasons Roblox Studio didn’t fire that event when I stopped play testing the game in studio, and again, everything works when I played in a published Roblox game.

1 Like

The issue is that sometimes the RemoteEvent fires multiple times, this is just an issue that has always occurred in my experience, so we fix it using debounce.

You’re basically saying “just fix the issue” without recommending how to actually fix it…

Using debounce is perfectly fine, you have suggested no other way of actually fixing this, and that’s because it’s a Roblox issue, you can’t just stop the remote from firing multiple times, so you solve this by using debounce

1 Like

I assume you used PlayerAdded/PlayerRemoving in a server script.
Probably the Studio is firing these signals before you connect the function to them.
So, probably you have some yielding function before PlayerAdded event.
The simpliest solution would be moving the PlayerAdded before you yield or using different threads.

PlayerRemoving doesn’t fire when you leave the game on some devices. I’m not really sure if it’s because of some setting in the Studio, but if you kick yourself using console command bar, the event will fire.

1 Like

That’s not a straight answer that I’m expecting.

Whatever the case is, whatever that suits for you, thats the solution.

Also, the solution you gave me won’t work. I even made sure that I connect that event on the first line of the script, and it won’t fire still sometimes.

No, there have never been an issue with remote events firing multiple times when called just once.

If you’re experiencing such issue and you’re certain it’s due to Roblox bug, why don’t you make a bug report?

There is literally so many posts on this devforum similiar to this one, about remote events firing more than once, and majority of them I would say have been solved by using the effective method of Debounce