Advertisement
HowToRoblox

RemoveArmor

Feb 25th, 2023
1,010
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.14 KB | None | 0 0
  1. local armorpieces = game:GetService("ReplicatedStorage"):WaitForChild("ArmorPieces")
  2.  
  3.  
  4. function removeFunc(plr:Player, armortype:string) --Putting equipped armor into a player's inventory
  5.    
  6.     local char = plr.Character
  7.    
  8.     if char and char:FindFirstChild("Humanoid") and char.Humanoid.Health > 0 then
  9.        
  10.         local inv = plr:WaitForChild("ArmorInventory")
  11.         local equipped = plr:WaitForChild("ArmorEquipped")
  12.         local currentArmor = equipped[armortype]
  13.  
  14.         if currentArmor.Value ~= nil then
  15.            
  16.             local healthGain = currentArmor.Value.Stats.Health.Value
  17.             local speedGain = currentArmor.Value.Stats.Speed.Value
  18.             char.Humanoid.MaxHealth -= healthGain
  19.             char.Humanoid.WalkSpeed -= speedGain
  20.            
  21.             if char.Humanoid.Health > char.Humanoid.MaxHealth then
  22.                 char.Humanoid.Health = char.Humanoid.MaxHealth
  23.             end
  24.            
  25.             for _, armorpiece in pairs(armorpieces:GetDescendants()) do
  26.                 if armorpiece.Name == currentArmor.Value.Name and armorpiece.Parent.Parent == armorpieces then
  27.                     armorpiece:Clone().Parent = inv
  28.                     break
  29.                 end
  30.             end
  31.            
  32.             currentArmor.Value:Destroy()
  33.             currentArmor.Value = nil
  34.         end
  35.     end
  36. end
  37.  
  38. return removeFunc
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement