I have a speedboost that when touched by my car enables an increase in the BodyThrust of the car for 3 seconds then returns it to normal speed… however if i try to turn the car during this boost, it disables the touched event and the car returns to normal speed upon me turning the car. How can I keep the touched event going while also turning the car? Keep in mind if i enter the boost area with my car already turning and i dont let go, it will keep the boost… basically however i enter the boost must be held in order for me to maintain the boost, anything i press during the boost will disable the boost. The script below:
local debounce = false
script.Parent.Touched:Connect(function(hit)
if debounce == false then
debounce = true
if hit:FindFirstAncestor("Car") then
print("hit")
local Car = hit.Parent
local Motor = Car.Engine
Motor.Thrust.Force = Vector3.new(-Car.DriverSeat.Throttle * Car.DriverSeat.Torque * 45000,0,0)
wait(3)
Motor.Thrust.Force = Vector3.new(-Car.DriverSeat.Throttle * Car.DriverSeat.Torque * 20000,0,0)
else
end
wait(1)
debounce = false
end
end)
function operate()
if script.Parent.Active.Value == true then
if script.Parent.DriverSeat.Throttle ~= 0 then
script.Parent.Manouver.Thrust.force = Vector3.new(0,script.Parent.DriverSeat.Throttle * script.Parent.DriverSeat.Steer * script.Parent.DriverSeat.TurnSpeed *1250,0)
else
script.Parent.Manouver.Thrust.force = Vector3.new(0,script.Parent.DriverSeat.Steer * script.Parent.DriverSeat.TurnSpeed * 450,0)
end
local drive = script.Parent.DriverSeat.Throttle * script.Parent.DriverSeat.Torque * 12000
script.Parent.Engine.Thrust.force = Vector3.new(-drive,0,0)
else
end
end
script.Parent.DriverSeat.Changed:connect(operate)
The speedboost is in a part… that part has the first script for the boost. Its a speedboost pad that once touched activates the speed in the vehicle touching it.
The second script is in the vehicle.
I have no issue with the thrust… the vehicle boosts when it touches the pad… the issue is that if i try to turn the vehicle during the boost, it stops the touched function.
local debounce = false
script.Parent.Touched:Connect(function(hit)
if debounce == false then
debounce = true
if hit:FindFirstAncestor("Car") then
print("hit")
local Car = hit.Parent
local Motor = Car.Engine
if Car.Active.Value == true then
Motor.Thrust.Force = Vector3.new(-Car.DriverSeat.Throttle * Car.DriverSeat.Torque * 45000,0,0)
wait(3)
Motor.Thrust.Force = Vector3.new(-Car.DriverSeat.Throttle * Car.DriverSeat.Torque * 20000,0,0)
end
else
end
wait(1)
debounce = false
end
end)
Edit: or should i be setting the value to true instead of making it an if then?
script.Parent.Touched:Connect(function(hit)
if not Car.Active.Value then
Car.Active.Value = not Car.Active.Value
if hit:FindFirstAncestor("Car") then
print("hit")
local Car = hit.Parent
local Motor = Car.Engine
Motor.Thrust.Force = Vector3.new(-Car.DriverSeat.Throttle * Car.DriverSeat.Torque * 45000,0,0)
wait(3)
Motor.Thrust.Force = Vector3.new(-Car.DriverSeat.Throttle * Car.DriverSeat.Torque * 20000,0,0)
end
wait(1)
Car.Active.Value = not Car.Active.Value
end
end)
function operate()
if script.Parent.DriverSeat.Throttle ~= 0 then
script.Parent.Manouver.Thrust.force = Vector3.new(0,script.Parent.DriverSeat.Throttle * script.Parent.DriverSeat.Steer * script.Parent.DriverSeat.TurnSpeed *1250,0)
else
script.Parent.Manouver.Thrust.force = Vector3.new(0,script.Parent.DriverSeat.Steer * script.Parent.DriverSeat.TurnSpeed * 450,0)
end
local drive = script.Parent.DriverSeat.Throttle * script.Parent.DriverSeat.Torque * 12000
if not script.Parent.Active.Value then
script.parent.engine.Thrust.Force = Vector3.new(-drive,0,0)
end
end
script.Parent.DriverSeat.Changed:Connect(operate)
Try this… and make sure Active isn’t being used anywhere else.