Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is my if statement only running once even though it is in a while wait loop?

Asked by 3 years ago
--variables
local body = script.Parent
local rightRay = Ray.new(body.Position,Vector3.new(0,0-10))
local leftRay = Ray.new(body.Position,Vector3.new(-10,0,0))
local backRay = Ray.new(body.Position,Vector3.new(10,0,0))
local vs = script.Parent.Parent.VehicleSeat
--start the car
vs.Throttle = 1
--do the movements every 1 second
while wait(1) do
    --this is to do trafic speed mantaince and crosswals
    local frontRay = Ray.new(body.Position,Vector3.new(0,0,-30))    
    local hit,Position = game.Workspace:FindPartOnRayWithIgnoreList(frontRay,{body})
    local crosswalk = game.Workspace.CrswlkObj
    if hit == crosswalk then
        print("Reached Cross walk")
        vs.Throttle = hit.Velocity.Z
        wait(1)
        vs.Throttle = 1 
    end

    --this is the line follower

end

Please help. Sorry if the answer is very simple. Thanks

1 answer

Log in to vote
-1
Answered by 3 years ago
Edited 3 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.
--variables
local body = script.Parent
local rightRay = Ray.new(body.Position,Vector3.new(0,0-10))
local leftRay = Ray.new(body.Position,Vector3.new(-10,0,0))
local backRay = Ray.new(body.Position,Vector3.new(10,0,0))
local vs = script.Parent.Parent.VehicleSeat
local RunService= game:GetService("RunService")
--start the car
vs.Throttle = 1
--do the movements every 1 second
RunService.RenderStepped:Connect(function()
    --this is to do trafic speed mantaince and crosswals
    local frontRay = Ray.new(body.Position,Vector3.new(0,0,-30))    
    local hit,Position = game.Workspace:FindPartOnRayWithIgnoreList(frontRay,{body})
    local crosswalk = game.Workspace.CrswlkObj
    if hit == crosswalk then
        print("Reached Cross walk")
        vs.Throttle = hit.Velocity.Z
        wait(1)
        vs.Throttle = 1 
    end

    --this is the line follower

end)
--ok
0
Sorry it does not work. Maybe I might be doing something wrong. mikey2019d 43 — 3y
Ad

Answer this question