Making a boost pad for a car

Making a boost pad for a car how it should work is when the car goes over the pad it gives the car a short boost in speed this is my code.

local BP = script.Parent
local descendants = game.Workspace.Cars:GetDescendants()

       for index, descendant in pairs(descendants) do
          BP.Touched:Connect(function()
	  if (BP.Touched) then
	VehicleSeat.Throttle = 10000 --may be changed to torque / speed
	   end
    end)
end
1 Like

should be if BP.Touched == true

2 Likes

Doesnt work for some reason when i got over it with the car it doesnt give the boost any ideas?

1 Like

.Touched is an event that fires, not a bool value. you should use BP.Touched:Connect()

2 Likes

Where at in the if statement?
Or somewhere else?

get rid of the if statement, the touched event fires whenever the part is touched so the if is not necessary

1 Like

Now im getting this errror Workspace.BoostPart.Script:7: attempt to index nil with ‘Throttle’

you have not declared a vehicleseat variable. Try this

local car, seat
BP.Touched:Connect(function(part)
    car = part:FindFirstAncestor("CAR NAME")
    if car then
        seat = car:FindFirstChildOfClass("VehicleSeat")
    end
    if seat then
        seat.Throttle = 10000
    end
end)

replace CAR NAME with the name of the car model, might error since I wrote this in the devforum editor

EDIT: I just realized FindFirstAncestor can return nil, I changed the code a bit

1 Like

Now it says Workspace.BoostPart.Script:7: attempt to index nil with ‘FindFirstChildOfClass’ This is the code

local BP = script.Parent
local descendants = game.Workspace.Cars:GetDescendants()


for index, descendant in pairs(descendants) do
BP.Touched:Connect(function(part)
	local seat = part:FindFirstAncestor("SpecialCar"):FindFirstChildOfClass("VehicleSeat")
	if seat then
		seat.Throttle = 10000
	end
end)
end

and this is the workspace
Yes1
Yes1

local car, seat
BP.Touched:Connect(function(part)
    car = part:FindFirstAncestor("SpecialCar")
    if car then
        seat = car:FindFirstChildOfClass("VehicleSeat", true)
    end
    if seat then
        seat.Throttle = 10000
    end
end)
1 Like

It still wont work i even changed it to torque to see if the numbers changed im gonna go to bed for tonight hopefully i can find a fix tomarrow!

It does not increase because the Throttle's maximum value a VehicleSeat can have is 1.
You should change the motors speed instead:

local YourVehicleSeat = script.Parent --Reference vehicle seat 

while wait() do
   REFERENCEYOURMOTORHERE.speeds = vehicleSeat.Throttle * 50 
end

If the VehicleSeat throttle was at 1, then it would be at 50 as this code is multiplying 50 on 1.

1 Like

Wait but where do i put this? The script is inside the boost part itself and i need to refrence more than one vehicle seat and how is the script suspose to know when the car touches the part to give it 50 motor speed?

You can get the vehicleseat by using .Touched events: BasePart | Roblox Creator Documentation

See more about motors and vehicleseat: VehicleSeat | Roblox Creator Documentation