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)
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)
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