So, I've been stuck with this small bit of code, which is vital for making a driving system work for me. When the value is changed, the code is meant to detect that change depending on the number the value holds. I've also noticed on load that the first while statement runs fine. Anyways here's the code:
while script.Parent.Accel.Value==0 do wait(.5) script.Parent.Parent.VehicleSeat.Torque=0 break end while script.Parent.Accel.Value==10 do wait(.5) script.Parent.Parent.VehicleSeat.Torque=.1 break end
I have no idea how this isn't working as in theory it should. Any help would be greatly appreciated. Cheers!
EDIT -- I noticed i messed up a little bit of the code, now i know that it doesn't work as i've trialed with it corrected. Sorry for any confusion!
Your first while loop runs once if the value is initially 0 and it sets the torque to 0. It immediately stops itself after the first iteration. The second while loop has the same condition and changes the torque back to .1.
while condition do -- code break end
is equivalent to
if condition then -- code end
because the loop can only run once. Since you're talking about changes, it makes sense to listen to the Changed event:
script.Parent.Accel.Changed:Connect(function(newValue) if newValue == 0 then script.Parent.Parent.VehicleSeat.Torque = .1 else script.Parent.Parent.VehicleSeat.Torque = 0 end end)
I can't tell if this is quite what you want to do. You say in theory your code should work but I have no idea what you think it's supposed to do.