How to make a local debounce for lava parts

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

3 Likes

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.

3 Likes

please link me a documentary on array

1 Like

ROBLOX calls them tables instead of arrays, but they’re essentially the same thing.

1 Like

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

1 Like

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.

1 Like

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.

1 Like

well how do i remove the player from the table

1 Like

You find the index where the player is at, then use table.remove(). Like so:

table.remove(playerTable,table.find(playerTable,player.Name))

1 Like

but it will ask me for the number value

1 Like

… Exactly? table.find() gives you a “number value.”

1 Like

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

1 Like

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.

1 Like