My goal is to make a drowning script. So while the head of the player is touching the water it should take away 10 from the humanoid health.
I've attempted this and came up with this but it is not working. This script is in StarterCharacterScripts.
--Variables
local water1 = workspace.water1
local water2 = workspace.water2
local humanoid = script.Parent.Humanoid
local name = script.Parent.Name
local isDrowing = false
local drowningDamage = 10
--Functions
local function onTouch(part)
if part.Parent.Name == name then
if part.Name == "Head" then
isDrowing = true
end
end
end
local function onTouchEnded(part)
if part.Parent.Name == name then
if part.Name == "Head" then
isDrowing = false
end
end
end
--While Under Water
while isDrowing == true do
humanoid.Health = humanoid.Health + (drowningDamage * -1) print("Drowing")
wait(1)
end
--Connect Functions
water1.Touched:Connect(onTouch)
water1.TouchEnded:Connect(onTouchEnded)
water2.Touched:Connect(onTouch)
water2.TouchEnded:Connect(onTouchEnded)

3 comments
About the debounce part you may wanna do that localy because if 2 people step on the brick and someone gets damaged the other guy won't for 1 second because of the debounce. You may want to do the debounce localy with a remote event.
Hmm, i think changing it from a SCRIPT to a LOCALSCRIPT may help :/
This would not work as Local Script. From Workspace you can run only "Normal" scripts.