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
local PlayerMilitaryClothingPants = 0
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
local PlayerMilitaryClothingPants = 0
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
local PlayerMilitaryClothingPants = 0
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)
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!
2 comments
What the hell I answered you
I haven't used it yet :/