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.
Get the world position and orientation of the handle.
Calculate the relative positions of the attached parts in the handle’s local space.
Teleport the handle to the desired position.
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