I am trying to create a viewmodel for my FPS game. I've just started and already ran into a problem.
I am trying to create two copies of the roblox character's arms, but if the player's torso is rotated in any way, the cloned parts appear in world space, and not in object space (in relation to the torso's current position and rotation)
How do I fix this? I've read up on CFrame:toObjectSpace(), but I am unsure about its usage.
Here is my code:
local character = game.Workspace.Dummy
local fakearms = {}
local welds = {}
local gun = game.ServerStorage.g36
local rarm = Instance.new("Part")
local larm = Instance.new("Part")
rarm.Size = Vector3.new(1,2,1)
rarm.BrickColor = BrickColor.new("Pastel Orange")
larm.Size = Vector3.new(1,2,1)
larm.BrickColor = BrickColor.new("Pastel Orange")
leftweld = Instance.new("Weld",character.HumanoidRootPart)
rightweld = Instance.new("Weld",character.HumanoidRootPart)
welds[1] = rightweld
welds[2] = leftweld
welds[1].Part0 = character.HumanoidRootPart
welds[1].Part1 = rarm
welds[2].Part0 = character.HumanoidRootPart
welds[2].Part1 = larm
rarm.Parent = character
larm.Parent = character
rarm.CFrame = CFrame.new(character.Torso.CFrame.p) * CFrame.new(1.5,0,0)
larm.CFrame = CFrame.new(character.Torso.CFrame.p) * CFrame.new(-1.5,0,0)

2 comments
Correct me if I'm wrong, but I think local gun = game.ServerStorage.g36 should be changed to local gun = game.ServerStorage["g36'].
That's true but it isn't really relevant to the problem at hand. Thanks anyway, though!