Touched event not working

I am making a parking barrier and I can’t get the .Touched event to work.

My Script:

local sensor = script.Parent:WaitForChild("Sensor")
local barrier = script.Parent:WaitForChild("Barrier")

sensor.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		barrier.HingeConstraint.TargetAngle = -90
		wait(10)
		barrier.HingeConstraint.TargetAngle = 0
	end
end)

Is the sensor a part or something else? Also, the game could be stuck on the “WaitForChild”. WaitForChild will yield any code until the child is found. If the child is found, then the code will be allowed to continue running. However, if the child is not being found, it won’t get to the .Touched function. Check your output which can be found in the “View tab” and see if there are any messages like: “Infinite yield possible while waiting for Senser”

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.