I’ve created in-game armor and I was wondering how I would make it where when you touch it, the armor gets welded to the players torso and it adds x amount of health. I would also like the armor to respawn.
Any help/feedback is greatly appreciated, thanks!
Welding armor to characters is actually really easy. I don’t know if this is a “trick” or not, but by doing this method it makes it super easy to weld parts to the character.
This also depends on what rig type your armor is for. If I wanted to weld a chestplate on an R6 rig, an easy way to do that is to put a brick into the chestplate (the exact size as the player’s torso) make it invisible and position it in the center of the chestplate. Then, just insert a weld into that newly made part (make sure all parts are welded in the chestplate model, you can use any freemodel welding script to accomplish this) and set the weld’s parts to both the player’s torso and itself. Ex:
weld.Part0 = invisible_core_part
weld.Part1 = character_torso
And it should appear correctly on the character rig.
As far as regening goes, I don’t even think you need it. Just create a Touched event on the part that gives players armor, have it clone each segment of the armor (chestplate, leggings, whatever else) and repeat the process I outlined for you above, it should work good.
Hope this helps!
I’d rather not use free models, also I am using the R6 rig. My armor is a model with two parts inside. I don’t know too much about welding and cframe so I’d like you to try to elaborate more on what i should do. thanks for the feedback!
Hi! As @C_Sharper pointed, a fast and reliable solution to this could be welding the armor directly to the player. For example, a script like this could work (you will have to put that invisible part, and set it as the model’s PrimaryPart):
local armor = workspace.Armor
local part = script.Parent -- the part that will 'activate' the script when touched
local debounce = false
part.Touched:Connect(function(hit)
local torso = hit.Parent:FindFirstChild("HumanoidRootPart") -- this assumes hit.Parent exists!
if debounce == false and torso then -- checks if whatever touched the part is a player/dummy
debounce = true
local newArmor = armor:Clone() -- backup
armor:SetPrimaryPartCFrame(torso.CFrame)
local weld = Instance.new("Weld", torso) -- add a weld constraint inside the HumanoidRootPart
weld.Part0 = torso
weld.Part1 = armor.PrimaryPart
hit.Parent.Humanoid.MaxHealth = hit.Parent.Humanoid.MaxHealth + x --define/substitute x number
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.MaxHealth
wait(5) -- how much time you want to wait until players can use the armor again
armor = newArmor
armor.Parent = workspace -- regen
debounce = false
end
end)
This article might help you understand the script better. If you’re unfamiliar with CFrames, this tutorial is perfect for you!
PD: I encourage you to try learning some scripting basics so you can make your very own code!
Thank you so much, I really appreciate it. I do have an issue though, the position the model welds to the torso is incorrect. It makes the model turn on its side (to the right).
You can fix that with a minimal change in the line 9 of the example script. Replace torso.CFrame
with this:
torso.CFrame:ToWorldSpace(CFrame.Angles(0, math.rad(90), 0)
If it doesn’t rotate correctly, play with the angle rotation (here, 90 degrees). There is more info about CFrame in the tutorial linked above.