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

How do you rotate a model while welding it to the character using CFrame?

Asked by 5 years ago
Edited 5 years ago
local char = script.Parent
local rarm = char:WaitForChild("Right Arm")
local rs = game:GetService("ReplicatedStorage")
local gun = rs:WaitForChild("M1911")

local gunclone = gun:Clone()
gunclone.Parent = char
local primpart = gunclone.PrimaryPart

local weld = Instance.new("Weld")
gunclone:SetPrimaryPartCFrame(rarm.CFrame + Vector3.new(0,1.5,0))
weld.Part0 = rarm
weld.Part1 = primpart
weld.C0 = rarm.CFrame
weld.C1 = primpart.CFrame
weld.Parent = rarm

What I'm trying to do is weld a model to a player's arm and then position is correctly by rotating it. I have accomplished welding it to the arm but I'm having problems rotating it. I tried using CFrame.Angles() but the model was positioned in some random space that caused my character to spin.

I changed line 11 to this. I don't think I am using this correctly.

gunclone:SetPrimaryPartCFrame(rarm.CFrame*CFrame.Angles(math.rad(90),math.rad(-90),0) + Vector3.new(0,1.5,0))

Picture of it without CFrame.Angles() https://gyazo.com/e2bd44a4861c3cf6d2f634092550706a

Video of it with CFrame.Angles() The model is the tiny thing spinning around my character. https://gyazo.com/1a271a2bd986af968e933207135d4619

Answer this question