Hi there, I'm currently trying to make a script that will set a vehicle seats maxspeed to 0 when it touches a sensor brick which has a bool value inside. The idea is that it would touch the brick and if the bool value inside the brick is false the seats maxspeed will go to 0 and then it would wait until the bool value changes to true at which point the vehicle seats maxspeed would return to its original value. Thanks :)
Here is the current script with the part that I'm not sure how to do written in internal commentary
local sig = script.Parent.Parent local top = sig.Top local btm = sig.Bottom local debounce = false local occupation = script.Parent.BlockOccupied script.Parent.Touched:connect(function(Part) if Part.ClassName == "VehicleSeat" then if debounce == false then debounce = true if occupation.Value == true then Part.MaxSpeed = 0 --wait until the bool value named "occupation" is false wait(5) debounce = false elseif occupation.Value == false then wait(3) top.BrickColor = BrickColor.new("Really black") top.Material = "SmoothPlastic" btm.BrickColor = BrickColor.new("Really red") btm.Material = "Neon" occupation.Value = true wait(5) debounce = false end end end end )
Use a while loop or a repeat loop that repeats till its false
local sig = script.Parent.Parent local top = sig.Top local btm = sig.Bottom local debounce = false local occupation = script.Parent.BlockOccupied script.Parent.Touched:connect(function(Part) if Part.ClassName == "VehicleSeat" then if debounce == false then debounce = true if occupation.Value == true then Part.MaxSpeed = 0 repeat wait() until occupation.Value == false wait(5) debounce = false elseif occupation.Value == false then wait(3) top.BrickColor = BrickColor.new("Really black") top.Material = "SmoothPlastic" btm.BrickColor = BrickColor.new("Really red") btm.Material = "Neon" occupation.Value = true wait(5) debounce = false end end end end )