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)
Whenever you wish to convert something into a string, try using tostring()
.
Example:
number = 5 words = "This is a string" print(words..tostring(number))
This is only an example of course, because usually print()
will usually recognize integers
In your case, you may need to convert couple different objects.
Go here for a little more info