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)
How does one put a Gun in the Camera without Messing with the player?
1 answer
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
6 comments
trying it
Perfect!
Nice indenting on the phone.
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.
Accept this poor man's answer :c
I apologize for not accepting sooner. I worked perfectly!
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
If my answer worker please accept
to accept press the accept button under the comment section it will help me amd help you