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.
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.
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.
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?