Make sure the HumanoidRootPart is anchored.
Thanks! Also, for people reading this, if you cannot see your gun even after you have applied any fixes make sure it is actually pointing forwards, as it can be facing the side and thus it appears that it is not attached to your humanoid root part correctly.
I don’t understand this line of code:
luaNewMotor.C0 = NewMotor.Part0.CFrame:inverse() * NewMotor.Part1.CFrame
After some googling I still do not properly understand what the C0 property of a motor6D is, and why was the inverse function used in this case?
I’m new to motor6D lol
C0 means the Part0’s offset. We need to inverse the CFrame fix the position of the part’s CFrame.
I still dont understand how the inverse function is used to ‘fix’ the position of the part’s (what is ‘part’s’? Is it C0 or C1) CFrame, and why do you multiply it by Part1.CFrame
I looked at this post: What is ```CFrame:Inverse()```?
Are you basically subtracting one CFrame from another? What is the purpose of this?
The Motor6D of C0 is the offset for Part0. Inversing the CFrame is also the same like doing ToWorldSpace. It’s something similar to that. We’re inversing because when we apply a Motor6D the Part1 would reposition itself and we need to offset the C0 to fix it.
I can’t download the ViewModel… Can you make it into a free model?
Sure thing. I’m not the original creator of this viewmodel though.
Can you please explain more when you say :Inverse() is like ToWorldSpace()? I dont see the comparison. Also :Inverse() switches all the numbers in a CFrame’s positive and negative signs around. Positive numbers becoming negative and negative numbers becoming positive.
(Correct me if I’m wrong) So from my understanding, you set the part0 and part1 in the Motor6D, what this does is moves part1 to part0 position by default, then you have to use offset property C0 to fix it, but then wouldn’t you have to offset C1 instead? Because isn’t that the brick that is repositioning itself? (thanks for your help )
Has anyone ever just used a viewport frame?
Wouldn’t that be much easier?
Sure you will need to calculate the light direction. But isn’t it much simpler to use? No need for messy formula, motor6d and welds. Just a simple view model and localscript.
Plus the gun will not clip through walls.
for some reason in This function:> function module.weldgun(gun)
local Main = gun.GunComponets.Handle
for i, v in ipairs(gun:GetDescendants()) do
if v:IsA(“BasePart”) and v ~= Main then
local NewMotor Instance.new(“Motor6D”)
NewMotor.Name = v.Name
NewMotor.Part0 = Main
NewMotor.Part1 = v
NewMotor.C0 = NewMotor.Part0.CFrame:inverse() * NewMotor.Part1.CFrame
NewMotor.parent = Main
end
end
end
it says in the newmotor.name = v.name line “ReplicatedSTorage.MainModule:13: attempt to index nil iwth ‘Name’”
my gun doesnt appear in my face.
local:
local gunmodel = game.ReplicatedStorage:WaitForChild(“Groza”)
local viewmodel = game.ReplicatedStorage:WaitForChild(“Viewmodel”)
local module = require(game.ReplicatedStorage.MainModule)
viewmodel.Parent = game.Workspace.Camera
module.weldgun(gunmodel)
module.equip(viewmodel, gunmodel)
game:GetService("RunService").RenderStepped:Connect(function(dt)
module.update(viewmodel, dt)
end)
module:
local module = {}
function module.update(viewmodel, dt)
viewmodel.HumanoidRootPart.CFrame = game.Workspace.Camera.CFrame
end
function module.weldgun(gun)
local main = gun.GunComponents.Handle
for i,v in ipairs(gun:GetDescendants()) do
if v:IsA("BasePart") and v ~= main then
local motor = Instance.new("Motor6D")
motor.Name = v.Name
motor.Part0 = main
motor.Part1 = v
motor.C0 = motor.Part0.CFrame:inverse() * motor.Part1.CFrame
motor.Parent = main
end
end
end
function module.equip(viewmodel, gun)
local handle = gun.GunComponents.Handle
local hrp_motor = viewmodel:WaitForChild("HumanoidRootPart").Handle
gun.Parent = viewmodel
hrp_motor.Part1 = handle
end
return module
edit:
by making the animations it just ignored it nvm
Hey! In the future, if you’re experiencing this try anchoring and unanchoring the parts. Just putting this here for future users having the same problem.
So I tried the tutorial but the character still spawns when I run the code how can I fix this?
Can you elaborate more or send a video showing this, I don’t quite understand on what you’re trying to say.
Like when I hit play the camera has the arms attached to it but my regular character still loads in
Yeah it is supposed to load in, when you go first person your character would go invisible. I don’t really see what’s going on here or the problem?
Woops I didn’t set the camera to go to first person my bad