Answered by
5 years ago Edited 5 years ago
I would use a dictionary.
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.
1 | game.Players.PlayerAdded:Connect( function (Player) |
2 | if playerDebounces [ Player.Name ] = = nil then |
3 | playerDebounces [ Player.Name ] = false |
7 | game.Players.PlayerRemoving:Connect( function (Player) |
8 | playerDebounces [ Player.Name ] = nil |
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).
01 | game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect( function (Player) |
02 | local existent = false |
03 | for i = 1 , #playerDebounces do |
04 | if playerDebounces [ i ] = = Player.Name then |
10 | playerDebounces [ Player.Name ] = false |
12 | if playerDebounces [ Player.Name ] = = false then |
13 | playerDebounces [ Player.Name ] = true |
15 | playerDebounces [ Player.Name ] = false |
And this is the completed portion.
03 | game.Players.PlayerAdded:Connect( function (Player) |
04 | if playerDebounces [ Player.Name ] = = nil then |
05 | playerDebounces [ Player.Name ] = false |
09 | game.Players.PlayerRemoving:Connect( function (Player) |
10 | playerDebounces [ Player.Name ] = nil |
13 | game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect( function (Player) |
14 | local existent = false |
15 | for i = 1 , #playerDebounces do |
16 | if playerDebounces [ i ] = = Player.Name then |
22 | playerDebounces [ Player.Name ] = false |
24 | if playerDebounces [ Player.Name ] = = false then |
25 | playerDebounces [ Player.Name ] = true |
27 | playerDebounces [ Player.Name ] = false |
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.