Moving a tool made from several parts

I have a system that teleports the tool from the player’s character when he is holding it, to a specific place. How I have done this is by teleporting the tool’s handle to that position. But if the tool is made of several parts welded to the handle, those welds brake and basically the handle gets teleported but the other parts stay behind.

How can I make all of the tool’s part to teleport with the handle, without braking their welds and keeping the same offset from the handle.

5 Likes

Install this plugin

Select your tool parts that you want to weld, then select Weld All in the plugin menu

But if I teleported the handle, wouldn’t the weld’s offsets change?

No, it should remain the same in the offset. You should be modifying Handle.Position or Handle.CFrame

1 Like

Use .CFrame or model:PivotTo, using .Position breaks welds.

1 Like
  1. Get the handle of the tool.
  2. Get the world position and orientation of the handle.
  3. Calculate the relative positions of the attached parts in the handle’s local space.
  4. Teleport the handle to the desired position.
  5. Adjust the positions of the attached parts based on their relative positions.

Example:

local tool = game.Players.LocalPlayer.Backpack.YourToolName

local destinationPosition = Vector3.new(10, 5, 10)

local handle = tool:FindFirstChild("Handle")
local parts = tool:GetChildren()

local partPositions = {}
for _, part in ipairs(parts) do
    if part ~= handle then
        partPositions[part] = handle.CFrame:pointToObjectSpace(part.Position)
    end
end

handle.CFrame = CFrame.new(destinationPosition)

for part, relativePosition in pairs(partPositions) do
    part.CFrame = handle.CFrame * CFrame.new(relativePosition)
end
1 Like

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