When I make a debounce in a server script, players that didn’t touch the lava part won’t get damaged. I want the player that touched the part to not get damaged for 0.7 seconds but all players dont get damaged
Add the player’s name to an array when they touch the lava, wait 0.7 seconds, then remove the player from the array. When a player touches the lava the script will check if they’re already in the array: if they ARE in the array, then the script doesn’t damage the player.
please link me a documentary on array
Ok, well how do I find in which number in the table the player is in? I can do table.find but that will only check if the player is in the variable
But that’s all you need to do: check if the player is in the variable. If the result of table.find() is nil then the player isn’t in the array, if it’s a number then the player is in the array.
you can do Table.insert to add the player to it. then use Table.find(theArray, playerName) or how ever you added the player. then Table.remove after the wait.
well how do i remove the player from the table
You find the index where the player is at, then use table.remove(). Like so:
table.remove(playerTable,table.find(playerTable,player.Name))
but it will ask me for the number value
… Exactly? table.find() gives you a “number value.”
well then how do i remove the player from the table since the code just continues to damage other players that step on the part
Here, maybe an example script will make it easier to understand:
local part = script.Parent
local playerArray = {}
part.Touched:Connect(function(hitPart)
local humanoid = hitPart.Parent:FindFirstChild("Humanoid") --Finds humanoid
if(humanoid) then
local playerName = humanoid.Parent.Name --Gets name of player
if(not table.find(playerArray,playerName)) then --Checks if player's name isn't in the playerArray
table.insert(playerArray,playerName) --Adds player's name to playerArray
humanoid.Health -= 10 --Deals damage
wait(0.7)
table.remove(playerArray,table.find(playerArray,playerName)) --Removes player's name from the playerArray
else --If the player's name IS in the array
print("Player is already hit!")
end
end
end)
This allows for each player to have their own 0.7 second cooldown between taking damage.