I would use a dictionary.
playerDebounces = {}
In this dictionary, you'll store a key for every player, and a boolean value, assigned to that key, defaulted to false, indicating whether or not they can fire the RemoteEvent.
We need to put every player in the dictionary.
game.Players.PlayerAdded:Connect(function(Player)
if playerDebounces[Player.Name] == nil then
playerDebounces[Player.Name] = false
else
end)
game.Players.PlayerRemoving:Connect(function(Player)
playerDebounces[Player.Name] = nil
end)
Whenever this RemoteEvent is fired, modify the value of the key that pertains to the player that fired the RemoteEvent.
The bit of code above doesn't account for players that are already in the game, it only accounts for players that have yet to either enter or leave the game. So, we have to make sure that the playerDebounces dictionary has a key for the Player that fired the RemoteEvent, and if it doesn't, create one and set it to false(because this certainly is the first time the Player is firing the RemoteEvent).
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(Player)
local existent = false
for i = 1, #playerDebounces do
if playerDebounces[i] == Player.Name then
existent = true
break
end
end
if not existent then
playerDebounces[Player.Name] = false
end
if playerDebounces[Player.Name] == false then
playerDebounces[Player.Name] = true
wait(5)
playerDebounces[Player.Name] = false
end
end)
And this is the completed portion.
playerDebounces = {}
game.Players.PlayerAdded:Connect(function(Player)
if playerDebounces[Player.Name] == nil then
playerDebounces[Player.Name] = false
else
end)
game.Players.PlayerRemoving:Connect(function(Player)
playerDebounces[Player.Name] = nil
end)
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(Player)
local existent = false
for i = 1, #playerDebounces do
if playerDebounces[i] == Player.Name then
existent = true
break
end
end
if not existent then
playerDebounces[Player.Name] = false
end
if playerDebounces[Player.Name] == false then
playerDebounces[Player.Name] = true
wait(5)
playerDebounces[Player.Name] = false
end
end)
I have a 6th sense telling me there's a much simpler and quicker solution than mine, assuming that mine even works to begin with. If anyone has a better solution, or even a working one, post it.
2 comments
Do the debounce in the LocalScript.
But then the exploits bro