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
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
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
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)
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?