Why does it say nil for the models(Please read!)

So i have been struggling with this for the past 3 hours trying to figure out why it is not working but i did not i thought it was my game that was the issue so i went to a clean baseplate and tried to see if it is my games issue but i got the same error from my other so i came here seeking some help on how to fix this big or error

this is the format for the models

This is the script:
image

this is the error
image
(the error is on line 3)

Can you guys tell me what is causing this issue because at this point i don’t even know

1 Like

Models is also not an object here, it is an array of multiple objects, therefore Touched wouldnt work just like that.

Try something like this

local Models = script.Parent:GetDescendants()

for i,v in Models do
v.Touched:Connect(function(Hit)
      print(Hit.Parent)
end)
end
2 Likes

Hi so I tried it out and at first it error so I tried a different method which is this:

local Models = script.Parent

for i, v in Models:GetDescendants() do
	if v:IsA("Part") then
		v.Touched:Connect(function(Hit)
			print(Hit.Parent)
		end)
	end
end

and oddly it printed this out do you know why?
image

1 Like

I’m assuming it touched an object that’s just in Workspace, so it printed workspace due to that ?? unsure

1 Like

Check if the player had touched them, .Touched events only work with physics(so anchored and anchored parts wouldn’t work), you would need to use :GetTouchingParts()

Try something like this:

local Models = script.Parent

for i, v in Models:GetDescendants() do
	if v:IsA("Part") then
		v.Touched:Connect(function(Hit)
       if hit.Parent:FindFirstChildOfClass("Humanoid") then
			print(Hit.Parent)
            end
		end)
	end
end

or

local Parts = script.Parent:GetDescendants()

for i,v in Parts do
	if v:IsA("BasePart") then
		local PartsTouching = v:GetTouchingParts()
		
		for i,v in PartsTouching do
			print(v.Name)
		end
	end
end
1 Like