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

How and can someone make this Try Button work and fix the error (2)?

Asked by 9 years ago

This is the script from BlueTaslem (thank you). When I used it with all the explanation he gave me. I mean A LOT of explanation, it gave an error in this script. I am sorry if I am being stupid here. This is the script that BlueTaslem answered:

function onClicked(player)
    local character = player.Character
    local clothing = character:GetChildren()
    local storage = Instance.new("Model")
    for _, cloth in pairs(clothing) do
        if cloth:IsA("Clothing") then
            cloth.Parent = storage
        end
    end
    wait()
    local newShirt = script.Parent.Parent.Parent.Clothes.Shirt:clone()
    local newPants = script.Parent.Parent.Parent.Clothes.Pants:clone()
    newShirt.Parent = character
    newPants.Parent = character
    wait(5)
    newShirt:Destroy()
    newPants:Destroy()
    for _, cloth in pairs(storage:GetChildren()) do
        cloth.Parent = character
    end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked) 


function moveClothes(from, to)
    for _, child in pairs(from:GetChildren()) do
        if child:IsA("Clothing") then
            child.Parent = to
        end
    end
end

function onClicked(player)
    local character = player.Character
    local clothing = character:GetChildren()
    local storage = Instance.new("Model")
    moveClothes(character, storage); -- Put original clothes safely away
    wait()
    moveClothes(script.Parent.Parent.Parent.Clothes:Clone(), character)
    -- Get a copy of the staged clothes, put them in the character
    wait(5)
    moveClothes(character, nil) -- Delete the show clothes
    moveClothes(storage, character) -- Put original clothes back
end

script.Parent.ClickDetector.MouseClick:connect(onClicked) 

-- Shorter (by 1/3)
-- Simpler (no loops, no ifs)
-- Clearer and more correct

This is the error:

21:44:52.770 - Clothes is not a valid member of Model
21:44:52.772 - Script 'Workspace.Man.TryButton.Part.Script', Line 11
21:44:52.772 - Stack End

This is the previous question that was answered: https://scriptinghelpers.org/questions/15180/what-is-wrong-with-this-script

0
Please don't ask the same question twice BSIncorporated 640 — 9y
0
On line 11, you accessed 'Clothes' incorrectly. Check your parenting. Goulstem 8144 — 9y
1
Why do you have nearly the same thing twice??? Read the code -- it doesn't make sense to redefine functions and reconnect them. The error in question sounds like it's because the model you have doesn't have "Clothes" there. Reorganize it so that it does, or change "script.Parent.Parent.Parent.Clothes" to the correct thing. BlueTaslem 18071 — 9y
1
old question epiclightining 0 — 6y

Answer this question