I made a script that puts a player's regular clothes back on when they chat a specific phrase. However when this script is carried out I get an error:
Workspace.clothes:28: bad argument #3 to 'PantsTemplate' (string expected, got Object)
I understand what this means but I don't know how to convert the PantsTemplate into a string. Here is the script:
game.Workspace.ChildAdded:connect(function(char)
if char:FindFirstChild("Humanoid") then
local p = game.Players:FindFirstChild(char.Name)
if p then
if char:FindFirstChild("Shirt") then
sh = char.Shirt.ShirtTemplate
else
sh = Instance.new("Shirt")
sh.Parent = char
sh.Name = "Shirt"
end
if char:FindFirstChild("Pants") then
pa = char.Pants.PantsTemplate
else
pa = Instance.new("Pants")
pa.Parent = char
pa.Name = "Pants"
end
end
end
end)
function onChatted(msg, recipient, speaker)
local source = string.lower(speaker.Name)
msg = string.lower(msg)
if (msg == "/clothes") then
speaker.Character.Pants.PantsTemplate = pa
speaker.Character.Shirt.ShirtTemplate = sh
end
end
function onPlayerEntered(newPlayer)
newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end)
end
game.Players.ChildAdded:connect(onPlayerEntered)

4 comments
Try using tostring() to convert something into a string, if its possible. Let me know if this works, I will make it an answer if it does.
It just gives me the same error.
Nvm it works
Mark the title with a big [SOLVED] at the end please!