My game involves 2 teams, Blue Team and Red Team. I already figured out from a YouTube video how to change the player’s shirt & pants with their team uniform, but I need help on how to go about adding a team hat (“accessory”). My hats are called Blue Helmet and Red Helmet. Mind you, it is not a hat that can be found on the catalog, it is a hat I made inside Roblox Studio.
Here is the script I currently have in ServerScriptService:
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
if player.Team == game.Teams["Red Team"] then
character:WaitForChild("Shirt").ShirtTemplate = "rbxassetid://6490264318"
character:WaitForChild("Pants").PantsTemplate = "rbxassetid://6501481472"
elseif player.Team == game.Teams["Blue Team"] then
character:WaitForChild("Shirt").ShirtTemplate = "rbxassetid://6490382191"
character:WaitForChild("Pants").PantsTemplate = "rbxassetid://6501493224"
else
end
end)
end)
local BlueHat = game.ServerStorage.BlueHat --Or wherever it is
local RedHat = game.ServerStorage.RedHat
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
if player.Team == game.Teams["Red Team"] then
local HatClone = RedHat:Clone()
HatClone.Parent = character
character:WaitForChild("Shirt").ShirtTemplate = "rbxassetid://6490264318"
character:WaitForChild("Pants").PantsTemplate = "rbxassetid://6501481472"
elseif player.Team == game.Teams["Blue Team"] then
local HatClone = BlueHat:Clone()
HatClone.Parent = character
character:WaitForChild("Shirt").ShirtTemplate = "rbxassetid://6490382191"
character:WaitForChild("Pants").PantsTemplate = "rbxassetid://6501493224"
else
end
end)
end)
local red = game.ReplicatedStorage.REDHAT -- replace with hat
local blue = game.ReplicatedStorage.BLUEHAT -- replace with hat
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local hum = character:WaitForChild("Humanoid",10)
if not hum then
print(player.Name .. " missing humanoid")
return
end
if player.Team == game.Teams["Red Team"] then
hum:AddAccessory(red)
character:WaitForChild("Shirt").ShirtTemplate = "rbxassetid://6490264318"
character:WaitForChild("Pants").PantsTemplate = "rbxassetid://6501481472"
elseif player.Team == game.Teams["Blue Team"] then
hum:AddAccessory(blue)
character:WaitForChild("Shirt").ShirtTemplate = "rbxassetid://6490382191"
character:WaitForChild("Pants").PantsTemplate = "rbxassetid://6501493224"
else
end
end)
end)