Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Help with this uniform script?

My goal is so that when the player respawns they are uniformed. Unfortunately, that isn't working..

local home;
local away;
function GetHome() -- To find the hometeam
	for i, v in pairs(game.Teams:GetChildren()) do
		if v:findFirstChild("home") then
			return v
		end
	end
	return nil
end

function GetAway() -- To find the away team
	for i, v in pairs(game.Teams:GetChildren()) do
		if v:findFirstChild("away") then
			return v
		end
	end
	return nil
end

home = GetHome(); --Set the variables
away = GetAway();

game.Players.PlayerAdded:connect(function(player) 
	player.CharacterAdded:connect(function(character)
		local a = player.TeamColor --Set the players teamcolor
		if a == home.TeamColor then --[[Find the team that corresponds to the teamcolor]]
			character.Shirt:remove() --Remove the shirt
			character.Pants:remove() --Remove the pants
			local shirt = home.Home.Shirt:Clone() --Set the shirt to be added
			local pants = home.Home.Pants:Clone() -Set the pants to be added
			shirt.Parent = character --Add the shirt
			pants.Parent = character --Add the pants
		elseif a == away.TeamColor then
			character.Shirt:remove()
			character.Pants:remove()
			local shirt = away.Away.Shirt:Clone()
			local pants = away.Away.Pants:Clone()
			shirt.Parent = character
			pants.Parent = character
		end
			
			
	end)
end)

4 comments

0

What's the problem?

0

When the character respawns the uniform isnt put on them.

0

Is there any error? What debugging have you done? Do you realize the script you've pasted here has a syntax error on line 31?

0

Yeah lol I added the comments

1 answer

Just a notice - Instead of directly removing the shirt/pants - check whether they have those or not. It will error if they don't have either of those.

Or assuming they have shirts/pants - you can change the ID to the away/home ID instead of adding/removing.

This discussion is preserved as it was. New answers, comments, and votes are closed.