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

How do I make it so that when a player joins there are different clothes each time?

So I have a game. In this game when people join I want them to have specific clothes. But I want it so that it randomizes between characters. So, say I join I get a blue shirt. Someone else joins they get a different shirt. Like that. This is what I have so far for shirt script. How could I add onto this.

game.Players.PlayerAdded:connect(function(Player) -- Once a player is added
Player.CharacterAdded:connect(function() -- Once a Character is added to the Player
if Player.TeamColor == game:GetService("Teams")["Gentlemen"].TeamColor then -- Check their team
wait(1) -- Give it a chance to load, now thinking about it ChildAdded might've been better
for _,v in pairs(Player.Character:GetChildren()) do -- Gather everything in their Character
if v:IsA("Shirt") or v:IsA("Pants") then -- Check if its a shirt or pants
v:Destroy() -- If it is, destroy it
end -- End the if statement
end -- End the for _,v in pairs statement
local Shirt = Instance.new("Shirt",Player.Character) -- Create new shirt
local Pants = Instance.new("Pants",Player.Character) -- Create new pants
Shirt.ShirtTemplate = "rbxassetid://164089580"
Pants.PantsTemplate = "rbxassetid://323913611"-- code here
end -- End the if statement
end) -- End the CharacterAdded function
end) -- End the PlayerAdded function

1 answer

You could store the possible shirt and pants asset ids in tables and then index a random asset in each table.

Example:

local redShirts -- Table of asset ids
local redPants -- Table of asset ids

local blueShirts -- Table of asset ids
local bluePants -- Table of asset ids

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		-- Delete old clothing

		local shirt = Instance.new("Shirt")
		local pants = Instance.new("Pants")

		if player.TeamColor == BrickColor.Red then
			shirt.ShirtTemplate = redShirts[math.random(#redShirts)]
			pants.PantsTemplate = redPants[math.random(#redPants)]
		else if player.TeamColor == BrickColor.Blue then
			shirt.ShirtTemplate = blueShirts[math.random(#blueShirts)]
			pants.PantsTemplate = bluePants[math.random(#bluePants)]
		end

		shirt.Parent = character
		pants.Parent = character
	end)
end)

If the shirts and pants should be paired up (i.e. shirt at index 1 should be paired with pants at index 1), then you can simply store the randomly generated index and use it to access both tables.

Example:

local index = math.random(#blueShirts)
shirt.ShirtTemplate = blueShirts[index]
pants.PantsTemplate = bluePants[index]

3 comments

0

Not brick color red, just to provide a random shirt each time a player joins.

0

Where do I put the id's?

0

In a table, and do you mean you want the people that join to have randomly assigned clothes regardless of their team colour?

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