I have a part with just a script attached to it. This is inside the script:
local trap = script.Parent
local RESET_SECONDS = 1
local isTouched = false -- Declare debounce variable
local function damagePlayer(otherPart)
local partParent = otherPart.Parent
local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
if humanoid then
if not isTouched then -- Check that debounce variable is not true
isTouched = true -- Set variable to true
humanoid.Health = humanoid.Health - 10
print("OUCH!")
wait(RESET_SECONDS) -- Wait for reset time duration
isTouched = false -- Reset variable to false
end
end
end
trap.Touched:Connect(damagePlayer)
This code does damage every second to players standing on the pad, but it doesn't damage players that stand still on the pad. A player has to move for the Touched event to fire.
How do you make a script that can detect any player in contact with the pad and deal damage even if the player is not moving?
