Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

touch is not a valid member of part?

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

1 comment

0

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

1 answer

✓ Accepted answer

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 (

This discussion is preserved as it was. New answers, comments, and votes are closed.