How can I change my Auto-Armor Equip script for Teams?

I am trying to changing a Auto Equip Armor Script to a Auto Equip Team Armor. But, I have no idea how to do so.

Script:

game.Players.PlayerAdded:Connect(onPlayerRespawned)
function onPlayerRespawned(newPlayer)
	local armor = game.ServerStorage.EpicArmor:Clone()
	armor.Parent = newPlayer.Character
	
	for index, armorParts in pairs(armor:GetChildren()) do
		for index, playerParts in pairs(newPlayer.Character:GetChildren()) do
			if playerParts:IsA("BasePart") then
				if armorParts.Name == playerParts.Name then
					armorParts.PrimaryPart.CFrame = playerParts.CFrame
					local weld = Instance.new("WeldConstraint")
					weld.Part0 = playerParts
					weld.Part1 = armorParts.PrimaryPart
					weld.Parent = armorParts.PrimaryPart
				end
			end
		end
	end
end
function onPlayerEntered(newPlayer)
	newPlayer.Changed:Connect(function (property)
		if (property == "Character") then
			onPlayerRespawned(newPlayer)
		end
	end)
end
game.Players.PlayerAdded:Connect(onPlayerEntered)

You could do something along the lines of checking if the players team is for example bravo team and if they are then clone this armor and weld it to them and if they are alpha team then do the same but different armor.

function equipArmor(player)
      local bravoArmor = game.ServerStorage.BravoArmor:Clone()
      local alphaArmor = game.ServerStorage.alphaArmor:Clone()

      if player.Team == Bravo then
            bravoArmor.Parent = player.Character
     else
            alphaArmor.Parent = player.Character
      end
end

Hmm, still can’t understand but I understand what you said ontop

Why are you using the .Changed event?

This event will fire when one of the properties within your Player are updated but it is not practical for a Respawning event. Instead, try using this event instead!

1 Like