Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-2

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

Asked by 6 years 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 -19 — 6y

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.

Why was this question closed?

2 answers

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
6 years 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 6 years 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 920 — 6y
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 2009 — 6y