Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Need help putting clothes on the character with a script?

Asked by 7 years ago

I made a script inside of a tool that is supposed to say when I click mouse button 1, equip these assets onto the character. However it doens't work and I don't know why. Can I get some help?

Here is my code

local shirtTemplate = "http://www.roblox.com/asset/?id=375845776" 

local pantsTemplate = "http://www.roblox.com/asset/?id=375845821" 

local faceID = "http://www.roblox.com/asset/?id=19398553" 

local delete_Tshirts = true

script.Parent.Mousebutton1click:connect(function()
    function changeClothing(p) 
    if (p.Character) then 
        local shirt = true 
        local pants = true 
        local face = true 
        if (shirtTemplate == "") then shirt = false end 
        if (pantsTemplate == "") then pants = false end 
        if (faceID == "") then face = false end 
        local S = Instance.new("Shirt") 
        S.Name = "Shirt" 
        S.ShirtTemplate = shirtTemplate 
        local P = Instance.new("Pants") 
        P.Name = "Pants" 
        P.PantsTemplate = pantsTemplate 
        for _,v in pairs(p.Character:GetChildren()) do 
            if (v.className == "Shirt") then 
                if (shirt) then 
                    v:remove() 
                end 
            elseif (v.className == "Pants") then 
                if (pants) then 
                    v:remove() 
                end 
            elseif ((v.className == "Part") and (v.Name == "Torso")) then 
                if ((delete_Tshirts) and (v:findFirstChild("roblox"))) then 
                    v.roblox:remove() 
                end 
            elseif ((v.className == "Part") and (v.Name == "Head")) then 
                if ((face) and (v:findFirstChild("face"))) then 
                    v.face.Texture = faceID 
                end 
            end 
            if (shirt) then 
                S.Parent = p.Character 
            end 
            if (pants) then 
                P.Parent = p.Character 
            end 
        end 
        print("Changed " .. p.Name .. "'s clothing") 
    else 
        print(p.Name .. "'s character was not found; function returned") 
        return 
    end 
end 
end)
0
it does not work because you use deprecated stuff hiimgoodpack 2009 — 7y
0
You used "function()" twice. Mayk728 855 — 7y

1 answer

Log in to vote
1
Answered by
Mayk728 855 Moderation Voter
7 years ago
Edited 7 years ago

The problem you have is that you've put a function inside a function, and the second function isn't being called at all.

local shirtTemplate = "http://www.roblox.com/asset/?id=375845776" 

local pantsTemplate = "http://www.roblox.com/asset/?id=375845821" 

local faceID = "http://www.roblox.com/asset/?id=19398553" 

local delete_Tshirts = true

script.Parent.Mousebutton1Down:Connect(function(p)
--Remove the second function, and put the variable "p" into the first one.
    if (p.Character) then 
        local shirt = true 
        local pants = true 
        local face = true 
        if (shirtTemplate == "") then shirt = false end 
        if (pantsTemplate == "") then pants = false end 
        if (faceID == "") then face = false end 
        local S = Instance.new("Shirt") 
        S.Name = "Shirt" 
        S.ShirtTemplate = shirtTemplate 
        local P = Instance.new("Pants") 
        P.Name = "Pants" 
        P.PantsTemplate = pantsTemplate 
        for _,v in pairs(p.Character:GetChildren()) do 
            if (v.ClassName == "Shirt") then 
                if (shirt) then 
                    v:Destroy()
                end 
            elseif (v.ClassName == "Pants") then 
                if (pants) then 
                    v:Destroy()
                end 
            elseif ((v.ClassName == "Part") and (v.Name == "Torso")) then 
                if ((delete_Tshirts) and (v:FindFirstChild("roblox"))) then 
                    v.roblox:Destroy()
                end 
            elseif ((v.ClassName == "Part") and (v.Name == "Head")) then 
                if ((face) and (v:FindFirstChild("face"))) then 
                    v.face.Texture = faceID 
                end 
            end 
            if (shirt) then 
                S.Parent = p.Character 
            end 
            if (pants) then 
                P.Parent = p.Character 
            end 
        end 
        print("Changed " .. p.Name .. "'s clothing") 
    else 
        print(p.Name .. "'s character was not found; function returned") 
        return 
    end 
end)

Also, you are using alot of deprecated classes. Here is what you should use instead.

:findFirstChild() is :FindFirstChild()
:remove() is :Destroy()
MouseButton1click is MouseButton1Down
:connect() is :Connect()
.className is .ClassName

That's it! Hope this helps.

Ad

Answer this question