I'm making this script where when I stand in this water it makes the player lose 5 health every 1 second they stand in the water.
wait(1) function onTouched(part) local h = part.Parent:findFirstChild("Humanoid") if h~=nil then h.Health = h.Health -5 end end script.Parent.Touched:connect(onTouched)
You need to add a debounce if you want the part to damage the player every 1 second.
local Disabled = false --debounce function onTouched(part) if not Disabled then -- If it's not disabled then Disabled = true -- disable :connect local h = part.Parent:findFirstChild("Humanoid") if h~=nil then h.Health = h.Health -5 end wait(1) Disabled = false -- enable :connect end end script.Parent.Touched:connect(onTouched)
There is actually a function for this!!
THIS WILL ONLY WORK IF YOU ARE USING TERRAIN WATER.
Here's basic code:
-- Put this in startercharacterscripts under starterplayer. while wait(1) do -- Run every second. if script.Parent.Humanoid:GetState() == Enum.HumanoidStateType.Swimming then -- Check if they are in terrain water. script.Parent.Humanoid:TakeDamage(1) -- Take damage. end end
That will only work if you are using terrain water as you say you are using water.