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

Why does this script not print something when an car goes at 40 speed?

Asked by 6 years ago

The script is supposed to print something if a car is going at 40 speed. Heres the script:

while wait() do
    local speed = script.Parent.Velocity.Magnitude
    if speed == 40 then
        print("you are going too fast")
    end
    wait()
end
0
Loops won't work at all. And if speed == 40 causes the error. try <= instead? cherrythetree 130 — 6y
0
That sadly didnt work. ieatandisbaconhair 77 — 6y
0
just because loops won't work. cherrythetree 130 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Instead of speed == 40 do speed >= 40 because the way you increase speed may make the speed go over 40, while skipping it. (like if you increase the speed by +3 or any number thats not a divisor of 40, the speed will never equal 40).

0
Thanks you so much, it worked! ieatandisbaconhair 77 — 6y
0
does it work without while wait() do? ieatandisbaconhair 77 — 6y
0
you can make it so that it checks every time the speed changes with the :Changed event radusavin366 617 — 6y
0
on what variable do i need to do that? ieatandisbaconhair 77 — 6y
0
on the magnitude, of course radusavin366 617 — 6y
Ad

Answer this question