How to Carry Objects Above of a moving Object

Hi i wanted to make a casual game, like “Work at a Pizza Place”.
i wanted to make Blocks Carryables in a truck.
but why this happens, and how i fix it?:

This is happening because the part isn’t actually on the truck per se. Since there is no friction when the truck starts moving the part just flies off. I’m not sure about the video as it looks like there’s door trying to hold it in, might just be a visual bug.

My recommendation is to add a weld constraint when putting it down. So when you put the part down, it will weld itself to the part(s) it’s touching. Then, when you pick the part back up, it will remove the welds.

An actual implementation of this might look like:

--pseudocode
function holdingmodule.place_down(part_being_held: BasePart)
 -- your other logic
 -- make sure that part_being_held is not anchored
 local touching_parts = part_being_held:GetTouchingParts()
 for _, part: BasePart in ipairs(touching_parts) do
   local weld = Instance.new("WeldConstraint", part_being_held)
   weld.Part0 = part_being_held
   weld.Part1 = part
 end
end

function holdingmodule.picking_up(part_being_held: BasePart)
 -- other logic
 for _, weld: Instance in pairs(part_being_held) do
   if not weld:IsA("WeldConstraint") then continue end
   weld:Destroy()
 end
end

Very very limited code explanation, but should get the point across. You’ll need to weld it in place to the truck before it starts moving. The reason why you need to do this, is because every part in Roblox is their own physics object and if a moving object touches it, it may slide. Even if one part moves, the other will move the exact amount the other direction to keep its original position.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.