So basically, I made a script for my AI car, and I want it to stop when something was in front of it, and that's what I made. But what make's me confused is that why does it keep driving when something is in front of it instead of stopping?
Script:
local leftDrive = script.Parent.Chassis.WheelRL.WheelMount.LeftDrive
local rightDrive = script.Parent.Chassis.WheelRR.WheelMount.RightDrive
local stopLight1 = script.Parent.LightParts.TailLightPart1
local stopLight2 = script.Parent.LightParts.TailLightPart2
script.Parent.StopDetector.Touched:Connect(function(hitstop)
if hitstop.Name == "BodyFrame" then
print("Stopping Car")
leftDrive.AngularVelocity = 0
rightDrive.AngularVelocity = 0
stopLight1.Material = Enum.Material.Neon
stopLight2.Material = Enum.Material.Neon
else
print("Driving Car")
leftDrive.AngularVelocity = 80
rightDrive.AngularVelocity = -80
stopLight1.Material = Enum.Material.SmoothPlastic
stopLight2.Material = Enum.Material.SmoothPlastic
end
end)
