Ad
Log in to vote
-2

how do make a gun(or other bricks) attached to the player? [closed]

Asked by 2 months ago

think of if you played phantom forces and you hit the deploy button, you automatically have the gun up and equipped. I don't like using tools for this because it feels wrong. I have only done basic scripting, and I cant find anything on how to do this.

1
Make a framework? Vexuss_Recon -14 — 2mo

Closed as Not Constructive by hiimgoodpack, lukeb50, abnotaddable, CootKitty, DeveloperSolo, Void_Frost, and Goulstem

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Hi.

Looks like you're using an ad blocker.

That's fine...

No, it really is.

Just, I mean, we put a lot of work into this site, you know?

It would be really really appreciated if you would turn off your ad blocker for our website...

We tried really hard to make our ads as unobtrusive as possible.

If you really hate ads, would you consider a $2 donation via Patreon?

Here's the link.

We love you. We hope you love us too.

.

..

...

Now back to your regularly scheduled Scripting Helpers....

...

..

.

2 answers

Log in to vote
1
Answered by
Goulstem 7591 Administrator Badge of Merit
1 month ago

Using the PlayerAdded and CharacterAdded events, you can weld objects onto the character model each time they spawn.

Example;

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        --Wait for the HumanoidRootPart
        local root = char:WaitForChild("HumanoidRootPart");
        --Create the object to weld
        local part = Instance.new("Part");
        part.Size = Vector3.new(3,3,3);
        part.CFrame = root.CFrame;
        part.Transparency = .5;
        part.BrickColor = BrickColor.new("Bright red");
        part.CanCollide = false;
        --Create the weld
        local w = Instance.new("Weld");
        w.Part0 = part;
        w.Part1 = root;
        w.Parent = part;
        part.Parent = char;
    end)
end)

To use this for a "gun", you would want to weld to the character's arm. "Shooting" is a matter of detecting user input using a LocalScript, and using Remotes to transfer the information to the server.

Ad
Log in to vote
-4
Answered by 2 months ago

Making your first First Person Shooter?

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)

This isn't my script but it'll work for your needs!

Best Regards.

1
CODEBLOCK!!! abnotaddable 712 — 2mo
1
"This isn't my script but it'll work for your needs!" So, is this why so many people are amused by how people make bots? hiimgoodpack 1487 — 2mo
Ad