Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i weld two parts together and make them move with each other?

Asked by 8 years ago

I am trying to combine two parts together for my admin tabs I am making, but they dont stay together, they move apart..

Any ideas?

local Part1 = Instance.new('Part', game.Workspace)
Part1.Anchored=true
Part1.Transparency=0.5
Part1.Size=Vector3.new(5,5,5)
Part1.CanCollide=false

local Part2 = Instance.new('Part', game.Workspace)
Part2.Anchored=true
Part2.Transparency=0.3
Part2.Size=Vector3.new(3,3,3)
Part2.CanCollide=false
Part2.CFrame = Part1.CFrame * CFrame.new(0,0,0)

game:GetService('RunService').Stepped:connect(function()
Part1.CFrame = CFrame.new(game.Players.LocalPlayer.Character.Torso.Position) * CFrame.new(0,0,-5)
end)

0
Try welding the parts together first. MrLonely1221 701 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

If you weld the parts together first they will be attached and then you can move the CFrame from there without them moving apart.

-- Put this script in 
local w = Instance.new("Weld", workspace); -- Creates a weld
w.Part0,w.Part1 = Part1,Part2; -- Sets which parts are welded
w.C0 = Part1.CFrame:inverse() -- Sets the CFrame for the first part to the CFrame of Part1
w.C1 = Part2.CFrame:inverse() -- Sets the CFrame for the second part to the CFrame of Part2

All together it would look like this

local Part1 = Instance.new('Part', game.Workspace)
Part1.Anchored=true
Part1.Transparency=0.5
Part1.Size=Vector3.new(5,5,5)
Part1.CanCollide=false

local Part2 = Instance.new('Part', game.Workspace)
Part2.Anchored=true
Part2.Transparency=0.3
Part2.Size=Vector3.new(3,3,3)
Part2.CanCollide=false
Part2.CFrame = Part1.CFrame * CFrame.new(0,0,0)

local w = Instance.new("Weld", workspace); -- Creates a weld
w.Part0,w.Part1 = Part1,Part2; -- Sets which parts are welded
w.C0 = Part1.CFrame:inverse() -- Sets the CFrame for the first part to the CFrame of Part1
w.C1 = Part2.CFrame:inverse() -- Sets the CFrame for the second part to the CFrame of Part2

game:GetService('RunService').Stepped:connect(function()
Part1.CFrame = CFrame.new(game.Players.LocalPlayer.Character.Torso.Position) * CFrame.new(0,0,-5)
end)

Hope this helps! If it does please accept this answer.

0
That worked a little! But I am trying to make it so i can have them both stick to each other, part two isnt in part 1 ;( BloxSimple 5 — 8y
0
What do you mean stick to each other? If you want them to float next to each other I would recommend using BodyPosition instead. MrLonely1221 701 — 8y
0
I am making admin tablets, I am trying to make the smaller block stay inside the bigger block with the smaller block moving out of the bigger block, i am trying to use cframe BloxSimple 5 — 8y
0
When I ran this the blocks werent together BloxSimple 5 — 8y
0
You could try making the CFrame of Part2 the CFrame of Part1 and then welding MrLonely1221 701 — 8y
Ad

Answer this question