Hello there!
Inside a script of mine i have a problem that the debounce i use breaks after a second player that runs the same script.
I want to have a seperate debounce for each player that tries to run that exact script.
I know that i have to use tables but i am not really good at them.
Is there a sollution to my problem?
local playerTable = {} -- create an empty table to store an index for everyone in
local someRemoteEvent = game.ReplicatedStorage.RemoteEvent-- an example event
local cooldownTime = 4 -- used 4 seconds as an example
game.Players.PlayerAdded:Connect(function(player)
if not playerTable[player.Name] then -- if there isn't an entry for the player already
playerTable[player.Name] = tick() -- Create a new entry in the table for each new player, and make the index their name so we can access it later
end
end)
game.Players.PlayerRemoving:Connect(function(player)
if playerTable[player.Name] then -- if there's an entry of the player in the table
playerTable[player.Name] = nil -- remove it from the table
end
end)
someRemoteEvent.OnServerEvent:Connect(function(player)
if tick() - playerTable[player.Name] > cooldownTime then -- If the time is greater than the cooldown time (so if more than 4 seconds have passed since the last time you set the player's index in the playerTable to tick()
playerTable[player.Name] = tick() -- set it back to tick() so it resets
--CODE HERE
end
end)
Get more info on how this works and the whole thread:
local Debounce
--code here blah blah
game.Players.PlayerAdded:Connect(function(plr)
if plr then
Debounce == true
if Debounce == true then
print("debounce = true")
elseif Debounce == false then
print("debounce = false")
end
end
end)