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

How to change player's Clothing?

So I want to make a game like phantom forces where they have their combat clothing but I want to make it where you can select different clothing depending on the team you are on and that which is basically changing the character's Clothing but I have no Idea how, I have a script I wanna give you guys and maybe you can correct it? I know I am asking you guys to make me one but I seriously have no idea function onclick (onclick) LoadPlayerAsset PlayerMiltaryClothing Clone() localplayer humanoid change= PlayerMiltaryClothing

function onclick (onclick)

end end

I know this is gonna get deleted I just wanted to try to see if anyone was gonna help I am a bad person ;_;

2 comments

0

What the hell I answered you

0

I haven't used it yet :/

1 answer

✓ Accepted answer

First of all, you could use the code block, it is much cleanier and easier to look at. Here is it on the code block:

function onclick (onclick) 
LoadPlayerAsset 
PlayerMiltaryClothing Clone() 
localplayer humanoid change= PlayerMiltaryClothing

function onclick (onclick)

end end

Okay, from your code I see you are a newbie at scripting. Don't worry, I'll help you.

First of all, LoadPlayerAsset a lone won't work, plus, it doesn't even exist. I get it, you are trying to change the clothing. But there is a different way to do so.

Secondly, PlayerMilitaryClothing Clone() won't work. PlayerMilitaryClothing needs to be defined in the script as a variable.

local PlayerMilitaryClothingShirt = 0 -- Put shirt ID
local PlayerMilitaryClothingPants = 0 -- Put pants ID

Now, everytime you use PlayerMilitaryClothingShirt it will return 0, as it is the value we defined.

Third fact, localplayer can only be accessed from LocalScripts, and not that way. Try game.Players.LocalPlayer instead. It will return the player the LocalScript belongs to.

Also, you don't need two onclick functions.

So this is our new code:

local PlayerMilitaryClothingShirt = 0 -- Put Shirt ID here
local PlayerMilitaryClothingPants = 0 -- Put Pants ID here

function onclick (onclick) 

end

But wait, we're still not over. Now, to connect the event, you must put this LocalScript inside an ImageButton or a TextButton.

For this, we use script.Parent -> TextButton/ImageButton``.MouseButton1Click MouseButton1Click runs every single time the player clicks on it.

We use :connect(function), in this case, :connect(onclick)

Now, we need to remove the player's shirt and pants. For this, we verify if it exists and then remove it.

if game.Players.LocalPlayer.Character:FindFirstChild("Shirt") then
	game.Players.LocalPlayer.Character.Shirt:Destroy()
end
if game.Players.LocalPlayer.Character:FindFirstChild("Shirt Graphic") then
	game.Players.LocalPlayer.Character:FindFirstChild('Shirt Graphic'):Destroy()
end
if game.Players.LocalPlayer.Character:FindFirstChild("Pants") then
	game.Players.LocalPlayer.Character.Pants:Destroy()
end

And then, we create a new one, by doing Instance.new('Shirt',game.Players.LocalPlayer.Character) By putting 'Shirt', we are creating a Shirt. By putting game.Players.LocalPlayer.Character, we make the shirt be inside it.

And then, we do ShirtTemplate/PantsTemplate to set the id. I RECOMMEND you to do id-1 because its the template most of the times.

Here is your code:

local PlayerMilitaryClothingShirt = 0 -- Put Shirt ID here
local PlayerMilitaryClothingPants = 0 -- Put Pants ID here

function onclick(onclick) 
	if game.Players.LocalPlayer.Character:FindFirstChild("Shirt") then
		game.Players.LocalPlayer.Character.Shirt:Destroy()
	end
	if game.Players.LocalPlayer.Character:FindFirstChild("Shirt Graphic") then
		game.Players.LocalPlayer.Character:FindFirstChild('Shirt Graphic'):Destroy()
	end
	if game.Players.LocalPlayer.Character:FindFirstChild("Pants") then
		game.Players.LocalPlayer.Character.Pants:Destroy()
	end

	local newShirt = Instance.new('Shirt',game.Players.LocalPlayer.Character)
	local newPants = Instance.new('Pants',game.Players.LocalPlayer.Character)

	newShirt.ShirtTemplate = "rbxassetid://"..tostring(PlayerMilitaryClothingShirt-1) -- tostring converts the number into text.
        newPants.PantsTemplate = "rbxassetid://"..tostring(PlayerMilitaryClothingPants-1)
end

script.Parent.OnMouseButton1Click:connect(onclick)

Hope this works it out and clears all of your doubts, while at the same time explaining you some Lua. Thanks!

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