Hello everyone! I am trying to help my younger brother with making his laser tag game. So I have taken most of the scripting process on my shoulders. I am trying my best.
Anyway, I made a system that assigns a specific outfit to the player depending on the team they are at (Blue or Red). I used two scripts for this.
The first one is a module script that stores the information for each outfit:
local TeamOutfits = {}
local player = game.Players.LocalPlayer
-- Function to set clothing
local function setOutfit(character, shirtTemplate, pantsTemplate)
local shirt = character:FindFirstChildOfClass("Shirt")
if not shirt then
shirt = Instance.new("Shirt")
shirt.Parent = character
end
shirt.ShirtTemplate = shirtTemplate
local pants = character:FindFirstChildOfClass("Pants")
if not pants then
pants = Instance.new("Pants")
pants.Parent = character
end
pants.PantsTemplate = pantsTemplate
end
-- Blue Team
function TeamOutfits.BlueTeam(character)
setOutfit(character, "rbxassetid://68057457", "rbxassetid://68057790")
end
-- Red Team
function TeamOutfits.RedTeam(character)
setOutfit(character, "rbxassetid://68057446", "rbxassetid://68057802")
end
-- For more outfits just copy and modify the above code 👍
return TeamOutfits
The second one is a local script in StarterPlayerScripts that does the assigning process (the print lines are simply for testing):
local player = game.Players.LocalPlayer
local Teams = game:GetService("Teams")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeamOutfits = require(ReplicatedStorage.TeamOutfits)
-- The code that assigns the outfits depending on the team the player is on.
local function assignTeamOutfit(character)
if player.Team == Teams.Red then
print("Player is on red team")
TeamOutfits.RedTeam(character)
elseif player.Team == Teams.Blue then
print("Player is on the blue team")
TeamOutfits.BlueTeam(character)
end
end
-- Give the player their respective outfit (if they exist)
if player.Character then
assignTeamOutfit(player.Character)
end
-- Make outfit work even on respawn
player.CharacterAdded:Connect(function(character)
assignTeamOutfit(character)
end)
It works very well so far, so I wanna expand on it further. I want to make it so that, alongside the clothes, it adds two accessories (four, but it’s two for each team) to the player. They’re not from the marketplace, they’re actually parts with meshes:
It seems they’re more complex to set up so I could really use some help here.
Thank you!
