So I recently made this script where a player's avatar changes upon entering the game. However, I want it to be where the avatar only changes upon the selection of a team. For example: Once a player joins the game, their character will be their normal selves. However, once they have selected a team, their avatar will change (shirt, pants, and hats) to the team they chose. So if they chose the "soldier" team, they will be wearing soldier apparel, but if they chose "civilian" they'd have civilian clothing.
There are multiple ways to do this. For the purpose of this, I will explain one way, and you can try to discover the rest based on this.
Note: This way will require an additional 2 random NBC accounts that the players will look like
First, let us set up our variables we will be using
-- Teams teamCiv = game.Teams["Team Name for Civilian"] teamSol = game.Teams["Soldier Team"] -- Player IDs CivID = "The Civilian dressed users ID here" SoldierID = "The Soldier dressed users ID here"
Now that we have that, let's create a function for each team, to change the Player's CharacterAppearance
function changeCiv(player) player.CharacterAppearance = "http://www.roblox.com/Asset/CharacterFetch.ashx?userId=" ..CivID end function changeSol(player) player.CharacterAppearance = "http://www.roblox.com/Asset/CharacterFetch.ashx?userId=" ..SoldierID end
Now that we have our functions, we can move on and figure our when we need to fire. We can do this first connect a PlayerAdded and a Changed event.
game.Players.PlayerAdded:connect(function (newPlayer) newPlayer.Changed:connect(function () if newPlayer.TeamColor == teamCiv.TeamColor then changeCiv(newPlayer) elseif newPlayer.TeamColor == teamSol.TeamColor then changeSol(newPlayer) end end) end)
Now let's put this all together:
-- Teams teamCiv = game.Teams["Team Name for Civilian"] teamSol = game.Teams["Soldier Team"] -- Player IDs CivID = "The Civilian dressed users ID here" SoldierID = "The Soldier dressed users ID here" function changeCiv(player) player.CharacterAppearance = "http://www.roblox.com/Asset/CharacterFetch.ashx?userId=" ..CivID end function changeSol(player) player.CharacterAppearance = "http://www.roblox.com/Asset/CharacterFetch.ashx?userId=" ..SoldierID end game.Players.PlayerAdded:connect(function (newPlayer) newPlayer.Changed:connect(function () if newPlayer.TeamColor == teamCiv.TeamColor then changeCiv(newPlayer) elseif newPlayer.TeamColor == teamSol.TeamColor then changeSol(newPlayer) end end) end)
NOTE: This is by far very inefficient, but it is the easiest way for me to explain to you a possible route. I recommend doing some more research and trying to do it yourself. Furthermore, this script was free written with no testing, so I apologize for mistakes that are bound to be here.
Sources:
http://wiki.roblox.com/index.php?title=Player
http://wiki.roblox.com/index.php?title=API:Class/Player/CharacterAppearance
(Assuming the team selection is using textbuttons) Make your script so when a player clicks the textbutton, then they would be changed depending on what team they chose.
I do not know the location of where you keep your clothes, so fill them in yourself on the first few lines. (BTW, this is for both teams, so just duplicate the script and configure them, and put them in the textbuttons.
ShirtID = PutShirtID PantsID = PutPantsID script.Parent.MouseButton1Click:connect(function() Shirt = Instance.new("Shirt") Pants = Instance.new("Pants") Shirt.Parent = script.Parent.Parent.Parent.Parent.Character -- Button must be directly under GUI. Not under a frame, or anything else. Pants.Parent = script.Parent.Parent.Parent.Parent.Character Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id="..ShirtID Pants.PantsTemplate = "http://www.roblox.com/asset/?id="..PantsID end)
Please accept answer if it worked!