Body Armor Parenting and Re-Locating

Hey there!

I am in need of assistance with creating a script. So I want to add body armour to a player (More specifically a Tac-Vest). The vest will spawn in, but will not be at the players torso (Upper Torso).

The Script I Am Using Currently:

local TCDVest = game.ServerStorage.TCDVest
local clonedVest = TCDVest:Clone()

game.Players.PlayerAdded:Connect(function(player)
	if player.Name == "pinchpotmonster" then -- My username will probably be change to a group rank once I have the appropriate group set up
		wait(5)
		clonedVest.Middle.Position = Vector3.new(game.Workspace.pinchpotmonster.UpperTorso)
	end
end)

Thank You.

2 Likes

Firstly you are putting an instance in a Vector, instead it should be 3 values. As well as the UpperTorso has a property called .Position which you can use to move it towards the player.

Secondly, inside of the PlayerAdded function you should have a CharacterAdded function, it will look as follows:

game:GetService("Players").PlayerAdded:Connect(function(player)
   player.CharacterAdded:Connect(function(character)
      -- Code
   end)
end)

You get the character instance in parameter with this function.

Furthermore, you are able to retreive a player’s character by using the .Character property of the player instance like so player.Character, else use the parameter of the .CharacterAdded function.

In addition, please use .CFrame instead of .Position, a CFrame is the orientation and the position of an instance (this is a basic explanation of it, there is more to it though).

As well was that you are just moving 1 part inside of the model, clonedVest, called Middle instead you can move the whole model by using Model:SetPrimaryPartCFrame(cframe), note you need to have the primary part set to be the middle (I will set the primary part in the script to middle as well just to be sure, please delete the line of code if you already did this).

Lastly, this should be run somewhere inside the PlayerAdded statement.
Note that you also forgot to change the Parent of the cloned vest to worspace or character.

Taking all of this to account your script would look something like this:

local TCDVest = game.ServerStorage.TCDVest


game.Players.PlayerAdded:Connect(function(player) -- player is a parameter of this function
	-- Have an if statement inside of the PlayerAdded function instead of the CharacterAdded function so you waste less space.
	if player.Name == "pinchpotmonster" then 
		player.CharacterAdded:Connect(function(character) -- character is a parameter of this function
			local clonedVest = TCDVest:Clone() -- clone the vest whenever the player respawns
			clonedVest:SetPrimaryPartCFrame(character.LowerTorso.CFrame) -- position and rotate the vest
			clonedVest.Parent = character -- parent the vest to make it visible
			-- Now last of all you have to weld it to the player!
		end)
	end
end)

Now the only things left which you should do is weld the primary part of the cloned vest to the lower torso of the player’s character and have the vest parented inside ServerStorage welded together already.

2 Likes

Hello,
Thank you for the assistance but I have a few questions/comments:

How would I do this?

And when the vest is spawned in this happens:
Screen Shot 2021-04-15 at 11.04.56 pm

I will be using qPerfectionWeld by @Quenty. qPerfectionWeld - Perfect welding for EVERY situat - Roblox

We will need to modify the code as this is used for tools.
Starting at line 215 image
We will edit the highlited text to “Model” like so image
Now we will put this script directly in the vest’s model:
image

Now the parts will all weld together every time.
Only thing to do is weld it to the player.

local weld = Instance.new("ManualWeld")
local P0 = clonedVest.PrimaryPart
local P1 = character.LowerTorso

weld.Part0 = P0
weld.Part1 = P1
weld.Parent = clonedVest.PrimaryPart

Now you might have to rotate the middle or offset it but after that it will work.

If you want to put it on the upper torso just replace all code with “LowerTorso” with “UpperTorso”.

Thank you very much for the help! :slight_smile: