I made a system for my basketball game where people are given their selected teams jerseys and then the warmup state starts, leading into the tipoff state. In the tipoff state, referees spawn to officiate the game and officially start the game with the tipoff. Whenever the referees spawn, their clothing would be replicated to whoever needed a jersey loaded for them.
This is how I load everyone’s jerseys when it reaches the warmup state.
function Task:LoadJerseys()
for _, Value in pairs(GameValues:GetChildren()) do
-- Skip other values
if Value.Name ~= "Home" and Value.Name ~= "Away" then
continue
end
-- Team variables
local TeamValue = Value
local Team = Value.Value
local JerseyType = Value.JerseyType.Value
-- Get all players
for _, Player in pairs(Team:GetPlayers()) do
if not Player.Character then
continue
end
-- // Variables
local Character = Player.Character
-- Clothing
local Shirt = Character:FindFirstChildOfClass("Shirt") and Character.Shirt
or Instance.new("Shirt", Character)
local Pants = Character:FindFirstChildOfClass("Pants") and Character.Pants
or Instance.new("Pants", Character)
-- // Init
Shirt.ShirtTemplate = 0
Pants.PantsTemplate = self:GetJersey(Team.Name,JerseyType)
end
end
end
This is how I load the referees for the Tipoff state
function RefMod:Init()
-- // Already existing referee check
for _, PossibleRef in pairs(Org.Referees:GetChildren()) do
if PossibleRef:IsA("Model") or PossibleRef.Name:find("Referee") then
return
end
end
-- // Init
-- Variables
local Preset = ServerStorage.Referees
-- Setup all refs
for _, Referee in pairs(Preset:GetChildren()) do
-- // Clone
local Obj = Referee:Clone()
Obj.Parent = Org.Referees
-- // Variables
local Root = Obj:FindFirstChild("HumanoidRootPart")
local Humanoid = Obj:FindFirstChild("Humanoid")
-- Info
local LoadedAnimations = {}
local LookAt = Root:FindFirstChild("LookAt") and Root.LookAt
or Instance.new("BodyGyro", Root)
LookAt.MaxTorque = Vector3.zero
local Type = tonumber(Referee.Name:sub(Referee.Name:len(), Referee.Name:len())) <= 2 and "Sideline"
or "Stationary"
-- // Setup
-- Animations
for _, Animation in pairs(AnimationFolder.Referee:GetChildren()) do
-- Animation obj check
if not Animation:IsA("Animation") then
continue
end
-- Valid animation ID
if Animation.AnimationId == "" or Animation.AnimationId == "rbxassetid://0" then
warn("Animation '"..Animation.Name.."' does not have a valid AnimationId")
continue
end
-- Load
local LoadedAnimation = Humanoid:LoadAnimation(Animation)
LoadedAnimations[Animation.Name] = LoadedAnimation
end
-- Collisions
for _, Part in pairs(Obj:GetChildren()) do
if not Part:IsA("BasePart") then
continue
end
Part.CollisionGroup = "Referees"
end
-- Info
self.Referees[Referee.Name] = {
["Obj"] = Obj,
["State"] = Type,
["LookAt"] = LookAt,
["Animations"] = LoadedAnimations
}
end
end
Not too sure if it’s a ROBLOX engine / replication issue, or it’s my code messing up.