Hello, I have a script, but this script prints everything except for “No right” and “No left”. This script doesn’t have any errors or warnings, but it doesn’t work. What is causing the script to not work? Thank you.
I posted many scripting support topic relating to this script because this script is keep on not working.
This is the script:
-- Variables
local car = game.Workspace.SelfDrivingCar
local forwardSensor = car.Sensor1
local rightSensor = car.Sensor2
local leftSensor = car.Sensor3
local road = game.Workspace.Road
local player = game.Workspace.HumanoidSensor
local rightSensorTable = {}
local leftSensorTable = {}
local touchingRightSensor = rightSensor:GetTouchingParts()
local touchingLeftSensor = leftSensor:GetTouchingParts()
local forward
local right
local left
print("Variables work")
spawn(function ()
-- Makes the car move forward
while wait(15) do
while wait() do
car:PivotTo(car:GetPivot() * CFrame.new(0, 0, -0.1))
print("Car moves forward")
end
end
end)
-- Checks if the road is touching the sensor.
for i, v in pairs(touchingRightSensor) do
print(v)
table.insert(rightSensorTable, v)
end
for i, v in pairs(touchingLeftSensor) do
print(v)
table.insert(leftSensorTable, v)
end
if table.find(touchingRightSensor, road) then
print("this works1")
right = true
else
right = false
end
if table.find(touchingLeftSensor, road) then
print("this works2")
left = true
else
left = false
end
spawn(function ()
while wait() do
print("wait works")
while true and wait() do
print("works works")
if right and not left then
print("No left.")
local turnCar = CFrame.Angles(0, -5, 0)
local drivingCar = car:GetPivot()
car:PivotTo(drivingCar * turnCar)
end
if left and not right then
print("No right.")
local turnCar = CFrame.Angles(0, 5, 0)
local drivingCar = car:GetPivot()
car:PivotTo(drivingCar * turnCar)
end
end
end
end)
Also, please don’t copy the script and use it for your game.