Changing Script/Pants

Hello, some days ago i got help for make a script to change shirt/pants script, with touching a part, it worked very well
but now i made a script for when player click a part.
but theres a problem
the script is not giving any error on console, and also not working, can someone help?

local cd = script.Parent.ClickDetector
local pants = script.Parent.Parent.Parent.Char.Pants

cd.MouseClick:Connect(function(tocado)
	if tocado.Character ~= nil then
		if tocado.Character:FindFirstChild("Pants") then
			local player = game.Players:GetPlayerFromCharacter(tocado.Parent)
			if tocado and tocado.Parent and tocado.Parent:FindFirstChild("Humanoid") and player then
				print(tocado.Parent.Name .. " - Changed Pants")
				
				local Pantsggj = player:WaitForChild("PlayerOldPantsId")
				
				local Character = tocado.Parent
				
				local shirt = Character:FindFirstChildOfClass("Shirt")
				
				if not shirt then	
					shirt = Instance.new("Shirt", Character)
					shirt.Name = "Shirt"
				end
				
				Character.Pants.PantsTemplate = pants
				wait(5)
				Character.Pants.PantsTemplate = Pantsggj.Value
			end
		end
	end
end)

The parameter you get in MouseClick is the player who clicked the part, some of the script is still suited to a touched

Try this


cd.MouseClick:Connect(function(tocado)
	local Character = tocado.Character
	if Character ~= nil then
		if Character:FindFirstChild("Pants") then
			if Character:FindFirstChild("Humanoid")then
				print(Character.Name .. " - Changed Pants")
				
				local Pantsggj = player:WaitForChild("PlayerOldPantsId")
				
				local pants = Character:FindFirstChildOfClass("Pants")
				
				Character.Pants.PantsTemplate = pants
				wait(5)
				Character.Pants.PantsTemplate = Pantsggj.Value
			end
		end
	end
end)
1 Like

Oops, change player to tocado

2 Likes

It fixed the error, but gave another error lol

Okay I really gotta look at my code carefully before sending, on that line, change it to

Character.Pants.PantsTemplate = pants.PantsTemplate
1 Like

Nah, its okay :smiley:
Sorry for disturb, but the script is not giving any error on console and not working again

It has to be because you’re setting the template to the pants you’re currently wearing and then setting to pantsggj. Is there already a Value in Pantsggj? If so, just do this

cd.MouseClick:Connect(function(tocado)
	local Character = tocado.Character
	if Character ~= nil then
		if Character:FindFirstChild("Pants") then
			if Character:FindFirstChild("Humanoid")then
				print(Character.Name .. " - Changed Pants")
				
				local Pantsggj = tocado:WaitForChild("PlayerOldPantsId")
				
				local pants = Character:FindFirstChildOfClass("Pants")
				
				Character.Pants.PantsTemplate = Pantsggj.Value
				wait(5)
				Character.Pants.PantsTemplate = pants.PantsTemplate
			end
		end
	end
end)
1 Like

Yes there already a value on Pantsggj
i need the script to the line

Character.Pants.PantsTemplate = pants.PantsTemplate

come first than the line

Character.Pants.PantsTemplate = Pantsggj.Value

so i made this

Character.Pants.PantsTemplate = pants.PantsTemplate
wait(5)
Character.Pants.PantsTemplate = Pantsggj.Value

and yeah, same problem
its not working, and not giving any error on console

Again, it’s because you’re setting the Template of the pants to the template of the Character’s pants, which does the same thing, I think you’re forgetting to set it to a specified template

cd.MouseClick:Connect(function(tocado)
	local Character = tocado.Character
	if Character ~= nil then
		if Character:FindFirstChild("Pants") then
			if Character:FindFirstChild("Humanoid")then
				print(Character.Name .. " - Changed Pants")
				
				local Pantsggj = player:WaitForChild("PlayerOldPantsId")
				
				local pants = "" --In the quotation marks add the url of the template
				
				Character.Pants.PantsTemplate = pants
				wait(5)
				Character.Pants.PantsTemplate = Pantsggj.Value
			end
		end
	end
end)

This wil lchange the pants to a template of your choosing and then change it back

1 Like

Oh, it worked, thanks for helping me at 6325782 time lol :heart:

1 Like