Log in to vote
0

# How does one put a Gun in the Camera without Messing with the player?

Asked by 3 years ago

How does one Put a gun in the camera and make it follow mouse without messing with the character? (Used to weld the gun to the head and put it in Camera)

0
If my answer worker please accept abnotaddable 915 — 3y
0
to accept press the accept button under the comment section it will help me amd help you abnotaddable 915 — 3y

### 1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

I'm assuming that your gun is just a model and not a tool. However if it is a tool, you should model everything together and then put the model outside of the tool and delete the tool instance.
When you are left with just your model, make sure there is a primarypart. Then put the model in replicatedstorage in a folder.
Make sure you have removed all other manual welds and other Weld Scripts.
We then want to put a local script in StarterCharacterScripts Which is a sub catagory of StarterPlayer.
In our script it will look like this:

local cam = workspace.CurrentCamera
local RepS = game:GetService("ReplicatedStorage")
local RunS = game:GetService("RunService")
local model = RepS:WaitForChild("Model"):Clone()
for i,v in pairs (model:GetChildren()) do
if v:IsA("BasePart") then
if v ~= model.PrimaryPart then
local weld = Instance.new("Weld")
weld.Part0 = model.PrimaryPart
weld.Part1 = v
weld.C0 = model.PrimaryPart.CFrame:inverse()
weld.C1 = v.CFrame:inverse()
weld.Name = v.Name
weld.Parent = model.PrimaryPart
end
end
end

model.Parent = cam

RunS.RenderStepped:Connect(function()
model:SetPrimaryPartCFrame(cam.CFrame*CFrame.new(-2,-2,-2))
end)


I wrote this on phone so I cannot guarantee that this will work

0
trying it Vexuss_Recon -19 — 3y
0
Perfect! Vexuss_Recon -19 — 3y
2
Nice indenting on the phone. hiimgoodpack 2009 — 3y
2
You don't have to compare the names, you can compare the instances on line 7. This way this would work even if the PrimaryPart was named the same as some other basepart inside the model. CootKitty 311 — 3y
View all comments (2 more)
1
Accept this poor man's answer :c Goulstem 8144 — 3y
0
I apologize for not accepting sooner. I worked perfectly! Vexuss_Recon -19 — 3y