Touched not a valid member of script

for i, v in pairs(script.Parent:GetChildren()) do
	v.Touched:connect(function(hit)
		if hit.Parent == game.Workspace.Wall then
			print ("false")
		end
	end)
end

i honestly dont know where i went wrong i basically just want a script that when a model touches a wall it does something i tried fixing this a few times writing the code differently but idk why

1 Like

Since you’re using :GetChildren() on the parent of the script, you will also get the script in the table of children returned. You must check if the child is a Base Part since base parts have the Touched event, not scripts.

for i, v in pairs(script.Parent:GetChildren()) do
    if v:IsA("BasePart") then
        v.Touched:connect(function(hit)
            if hit.Parent == game.Workspace.Wall then
                print ("false")
            end
        end)
    end
end
5 Likes

thx i was thinking of something completely different which made me confused lol

thx you so much :slight_smile: u helped me too