Hello everyone! I am trying to create a script where if the car from behind hits the car in front, the car in front will gain +10 MaxSpeed and then after 5 seconds it will decrease by 2 every 2 seconds. However, when I try to run this script in Studio, It keeps giving me this message, " attempt to index nil with 'VehicleSeat' " Do you know how to fix this problem?
local currentMaxSpeed = Model.VehicleSeat.MaxSpeed local speedBoost = 10 local speedFallOff = -2
function collided(hit) if hit.Name=="RearDraftingPart" then
VehicleSeat.MaxSpeed = currentMaxSpeed + speedBoost
wait(5)
VehicleSeat.MaxSpeed = currentMaxSpeed + speedBoost + speedFallOff
wait(2)
VehicleSeat.MaxSpeed = currentMaxSpeed + speedBoost + speedFallOff + speedFallOff
wait(2)
VehicleSeat.MaxSpeed = currentMaxSpeed + speedBoost + speedFallOff + speedFallOff + speedFallOff
wait(2)
VehicleSeat.MaxSpeed = currentMaxSpeed + speedBoost + speedFallOff + speedFallOff + speedFallOff + speedFallOff
wait(2)
VehicleSeat.MaxSpeed = currentMaxSpeed
else
VehicleSeat.MaxSpeed = currentMaxSpeed
end end
script.Parent.Touched:connect(collided)

2 comments
Thank you for the Feedback, jundell. I will look into another way of writing it.
I have returned I did a couple of modifications to the script and it works just as how I imagined it to work, THANK YOU SO MUCH JUNDELL FOR THE HELP :D