Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

2 comments

0

If my answer worker please accept

0

to accept press the accept button under the comment section it will help me amd help you

1 answer

✓ Accepted 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

0

trying it

0

Perfect!

2

Nice indenting on the phone.

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.

1

Accept this poor man's answer :c

0

I apologize for not accepting sooner. I worked perfectly!

This discussion is preserved as it was. New answers, comments, and votes are closed.