You almost have it. You can use a https://developer.roblox.com/en-us/api-reference/class/BodyPosition, like you said. However, this doesn’t use the assemblies local directions when moving it. To account for this you will have to continually update it’s direction to the direction you want to go in.
However, the legacy BodyMover’s have all (mostly) been superseded by newer body movers. In this case you can try learning about and using the https://developer.roblox.com/en-us/api-reference/class/VectorForce body mover. It accounts for some needs like this, is just as easy (if not easier) to use, and give you more control over the force applied to the object without having to script the intended behavior yourself. To set up such a system like a launch pad for a go-kart I would do something like this:
- Create an https://developer.roblox.com/en-us/api-reference/class/Attachment in the https://developer.roblox.com/en-us/api-reference/property/Model/PrimaryPart (I’m guessing it’s grouped in a model) of the go-kart (in this case I’m guessing you want this to be the
DriveSeat, although it’d be best to set it to the chassis of the go-kart) - Move this attachment to where you want the force applied to on the go-kart. This step is necessary if you want the power applied to the back wheels or front wheels. Otherwise you can set it’s position to somewhere in-between or just set the https://developer.roblox.com/en-us/api-reference/property/VectorForce/ApplyAtCenterOfMass to
true. - Create a
VectorForceobject in thePrimaryPartand set it’s https://developer.roblox.com/en-us/api-reference/property/Constraint/Attachment0 to the previously created attachment. Also make sure the https://developer.roblox.com/en-us/api-reference/property/VectorForce/RelativeTo property is relative toAttachment0. Then set the https://developer.roblox.com/en-us/api-reference/property/VectorForce/Force property to the https://developer.roblox.com/en-us/api-reference/datatype/Vector3 relative direction you want the force to be applied in. Since the force should be relative to the go-kart, you only have to set it once. You an also rename it to “Boost” or something. - When the go-kart drives over the launch pad, check if the https://developer.roblox.com/en-us/api-reference/property/Constraint/Enabled is enabled. If it isn’t, then set it to true. You can then wait a certain amount of time and then switch it back to disabled.
For step number 4 the launch pad script can look something like this:
local touched = {} -- array to cache already-touched parts -- this is basically a security blanket
LaunchPart.Touched:Connect(function(hit)
if (hit.Name == "FL") and not table.find(touched, hit) then
table.insert(touched, hit)
local boost = hit.Parent.Parent.DriveSeat:FindFirstChild("VectorForce")
if not boost.Enabled then
boost.Enabled = true
task.wait(2) -- custom delay for how long you want the boost to last
boost.Enabled = false
table.remove(touched, table.find(touched, hit)) -- we have to find the position of the part in the table again because it may have updated from other entries being removed
end
end
end)
P.S.
I noticed in your code you used the parent parameter for the Instance.new constructor.
While this is not necessarily a bad thing to do, it can affect performance, especially when you are creating many objects at once. You can read this post that explains why.