I've got a while true loop that detects a change in a value and implements that change onto a vehicle seat, It used to work perfectly but now can't seem to detect the change in value. It works while the value is at 0 but once it hits 10 then it doesn't detect that change. I'm abit baffled and another while true loop that detects value changes works perfectly to this day so i'm a tad baffled as to where I've gone wrong, anyways here's the code:
while true do wait(.5) if script.Parent.Accel.Value==0 then script.Parent.Parent.VehicleSeat.Torque=0 end if script.Parent.Accel.Value==10 then script.Parent.Parent.VehicleSeat.Torque=0.3 end end
The script shares the same parent as the value, so everything is where its supposed to be, its been months of nothing working so any feedback would be highly appreciated, cheers for your time guys!
Instead of a while loop
you can use a .Changed
event
Links to help you learn more:
local Accel = script.Parent.Parent.Accel -- make this a variable for easy access local VehicleSeat = script.Parent.Parent.VehicleSeat -- make this a variable for easy access local function Changed(Value) -- Value is the new value of Object Accel if Value == 0 then -- Check to see if Value is 0 VehicleSeat.Torque = 0 elseif Value == 10 then -- if value does not = 0 then check to see if it = 10 VehicleSeat.Torque = 0.3 end end Accel.Changed:Connect(Changed) -- Connect Changed function