So basically I am trying to make a brick that slowly reduces your health but if you are not touching it anymore, you stop losing health. This is my attempt but it doesnt work.
function damageplr(hit) wait(1.5) if hit.Parent.Head then hit.Parent:FindFirstChild("Humanoid").Health = hit.Parent:FindFirstChild("Humanoid").Health - 5 end end function TouchEnd(hit) end script.Parent.Touched:connect(function(hit) wait() repeat damageplr() until TouchEnd() hit.Anchored = false end) script.Parent.TouchEnded:connect(TouchEnd) script.Parent.Touched:connect(damageplr)
This could do the job, dont know if it works I dont have time to test it, But worth a try =)
script.Parent.Touched:connect(function(hit) pcall(function() hit.Parent.Humanoid:TakeDamage(5) end) end)
Here is an answer
works as of july 7 2018
wait(1) function onTouched(part) local h = part.Parent:findFirstChild("Humanoid") if h~=nil then h.Health = h.Health -1 --Change that number to the ammount of Health you want to decrease end end script.Parent.Touched:connect(onTouched)
now i know this was already answered but that didnt work for me and i made one without the pcall
function OnTouch(hit) hit.Parent.Humanoid:TakeDamage(5) end script.Parent.Touched:Connect(OnTouch)(hit)
it works for me and i hope this works for you
Yes,actually you can just keep doing (hit.Parent.Humanoid.TakeDamage(5), do it 20 times cause 5 * 20 is 100 and thats all the health a player on roblox has hope this helps