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)
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.