function onTouched(part) local h = part.Parent:findFirstChild("Humanoid")
h.Health = h.Health -25 wait(2) h.Health = h.Health -5
end
script.Parent.Touched:connect(onTouched)
It seems the parent of the part does not have an humanoid maybe? try this:
function onTouch(part) if part.Parent:FindFirstChild("Humanoid") then local h = part.Parent.Humanoid h.Health = h.Health - 25 wait(2) h.Health = h.Health - 5 else print(part.Parent.Name, "does not have an humanoid!") end end script.Parent.Touched:Connect(onTouch)
Keep in mind there is no cooldown between touches, so the Touched event will fire infinitely as long as long as the part is being touched, if you don't want that to happen, you can add a cooldown using debounce or something, like this:
local TimeBetweenTouches = 2 local debounce = false function onTouch(part) if debounce == false then debounce = true if part.Parent:FindFirstChild("Humanoid") then local h = part.Parent.Humanoid h.Health = h.Health - 25 wait(2) h.Health = h.Health - 5 else print(part.Parent.Name, "does not have an humanoid!") end wait(TimeBetweenTouches) debounce = false end end script.Parent.Touched:Connect(onTouch)