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

touch is not a valid member of part?

Asked by 5 years ago
Edited 5 years ago

Alright, So I'm extremely new to scripting, Learning obviously. I found a tutorial on how script a NPC / Model onto someone, but every time I go to try get clothing on it says,

touch is not a valid member of part

Here is the code

script.Parent.touch:connect(function(hit)
    if (hit.Parent:FindFirstChild("Humanoid"))then
        --local plr = game.players:FindFirstChild(hit.Parent.Name)

        local plrPants = hit.Parent:FindFirstChild("Pants")
        if (plrPants) then
            plrPants:remove()
        end

        local plrShirt = hit.Parent:FindFirstChild("Shirt")
        if (plrShirt) then
            plrShirt:remove()
        end

        local newClothingPants =script.Parent.Parent.NPC.Pants:Clone()
        local newClothingShirt =script.Parent.Parent.NPC.Shirt:Clone()

        newClothingPants.Parent = hit.Parent
        newClothingShirt.Parent = hit.Parent

    end
end)

Any help would be appreciated

0
Lua is case sensitive and unforgiving to spelling mistakes as well, use script.Parent.Touched:Connect(function(hit)) instead on line 1 Vulkarin 581 — 5y

1 answer

Log in to vote
0
Answered by
proIua 32
5 years ago
Edited 5 years ago

There is no event called "touch", it is called "Touched!" The proper code would be:

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid")then
        --local plr = game.players:FindFirstChild(hit.Parent.Name)

        local plrPants = hit.Parent:FindFirstChild("Pants")
        if (plrPants) then
            plrPants:remove()
        end

        local plrShirt = hit.Parent:FindFirstChild("Shirt")
        if (plrShirt) then
            plrShirt:remove()
        end

        local newClothingPants =script.Parent.Parent.NPC.Pants:Clone()
        local newClothingShirt =script.Parent.Parent.NPC.Shirt:Clone()

        newClothingPants.Parent = hit.Parent
        newClothingShirt.Parent = hit.Parent

    end)

A simple typo my friend, accept my answer if you want, please. Also note that :connect is deprecated, use :Connect, and remove() is also deprecated, but keep that if you like. And it is also end), not end, because you are closing that (

Ad

Answer this question