Slow client connections lead to functions getting spammed

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    My game works as follows: player clicks a button, fires a RemoteEvent, button dissapears, server side script runs, button reappears. The entire process takes about seven seconds, which is intentional.
    I want to ensure that even through bad connections, the function only runs one time when fired, even when lag makes the button vulnerable to being spam-clicked.

  2. What is the issue?
    However, I’ve noticed that if the player has a slow connection/device, the button will not disappear in moments of lag, and a few seconds later it will spam the function without the seven second process. I hope this makes sense.

  3. What solutions have you tried so far? I don’t exactly know how to describe this, and the DevForum posts didn’t exactly help.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

--Obviously my code doesn't actually look like this, it's just an idea of what the function does.
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")

game.Players.PlayerAdded:Connect(function(player)
	game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function()
		--make this number value go up
		
		--make this boolean value false
		
		--make button invisible (through boolean)
		
		wait(.5)
		
		--do something
		
		wait(.5)
		
		--do something
		
		wait(.5)
		
		--do something
		
		--if statement
		
		--else if statment
		
		--award badge
		
		wait(2)
		
		--make button visible again
		

end)		
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

I would probably make a table of players currently in use, and return if player is found within that table,

PlayersUsing = {}

and index using player.Name

ex:

if not PlayersUsing[player.Name] then

PlayersUsing[player.Name]=true
else
--due to already in use
return
end

Just a simple
if <name of the boolean> == false then
<name of the boolean> = true

in the beginning of the function should do the trick.