Hello,

I am trying to make a barrier, where when you touch it, it damages you. Since CanCollide is off, I don't think it can detect when the player stops touching the part. Also, If I don't do this loop, the script won't detect that the player is still in the wall.

Anyways, here is the script

local part = script.Parent

part.Touched:Connect(function(hit)
	if hit.Parent.Humanoid then
			if hit.Parent.Humanoid.Health > 0 then
				while wait(3) do
				hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 30 
					-- I want it to repeat until the player stops touching the wall.	
			end
		end
	end

Anyone know how to fix this script?

Thanks!

1 comment

0

You can use FindPartsInRegion3 (https://developer.roblox.com/en-us/api-reference/function/WorldRoot/FindPartsInRegion3) to do this without any part middle man. Its much cleaner. And it fixes your problem as well.