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.
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
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)
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.
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.
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.
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.
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.
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
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.
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.
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