GetChildren() only getting 1 child

local TeleporterFolder = game.Workspace.NPCsci.Teleporters:GetChildren()
local TeleportPosition = CFrame.new(game.Workspace.NPCsci.Teleporters.B.Position)

--
--[[
game.Players.PlayerAdded:Connect(function(player)
	local backpack = player:WaitForChild("Backpack")
	if backpack then
		local Part = backpack:WaitForChild("Suitcase").detect
		if Part then
			Part.Touched:Connect(function(hit)
				if hit == partToLookFor then
					Part.CFrame = TeleportPosition
				end
			end)
		else
			print("Part is equal to nil")
		end
	else
		print("Backpack is equal to nil")
	end
end)
game.Players.PlayerAdded:Connect(function(player)
		local suitcase = script.Parent.Parent.Parent.Detector:WaitForChild("Tool").detect
		suitcase.Touched:Connect(function(hit)
			print("test")
			if hit == partToLookFor then
				suitcase.CFrame = TeleportPosition
			end
		end)
		
		
		
	end)
]]




for i,v in ipairs(TeleporterFolder) do
	if v:IsA("BasePart") then
		local partToLookFor = v
		game.Players.PlayerAdded:Connect(function(player)
			local suitcase = script.Parent.Parent.Parent.Detector:WaitForChild("Tool").detect
			suitcase.Touched:Connect(function(hit)
				print("test")
				if hit == partToLookFor then
					suitcase.CFrame = TeleportPosition
				end
			end)
		end)
	end
end

This is my script above i dont know why is it doing that

1 Like


It is showing this error for some reasons.

what are you trying to do with this script i dont see the A reference but I do see where you have have this making multi connections to the player added which should be declared outside of the for loop

what exactly are you trying to achieve with this script

Oh, I forgot to remove that earlier. Is that the one who is making the error

GetChildren:() only get the children of the said instance. It doesn’t get the children of children of that instance.
Maybe that’s the problem?
If you want to get the children of children as well use GetDescendants()
I couldn’t understand what is the point of your script so I thought this might be the issue. If it isn’t then good luck.
Also if possible show a screenshot of the “Teleporters” in the explorer.

image
Here you go .

I am trying to get the children of Teleporters with the name A in my script. My script point is to teleport the tool to another part.


I am gonna try to use GetDescendants and see if it works.

image
I tried using getdescendants and it still shows the same error at output. I don’t know why is GetChildren nor GetDescendents is already getting a children

I think there is a small problem.
it says "A is not a valid member of Part “Workspace.NPCsci.Teleporters.A”
Here it is trying to find A part inside the A part which doesn’t exist according to the screenshot of explorer you sent earlier.
Get the children of Teleporters not A

How do I do that? My script is already getting childrens of Teleporter


local TeleporterFolder = game.Workspace.NPCsci.Teleporters:GetDescendants()
local TeleportPosition = CFrame.new(game.Workspace.NPCsci.Teleporters.B.Position)

for _,v in pairs(TeleporterFolder) do
	local partToLookFor = v.A
	local suitcase = script.Parent.Parent.Parent.Detector:WaitForChild("Tool").detect
	suitcase.Touched:Connect(function(hit)
		print("test")
		if hit == partToLookFor then
			suitcase.CFrame = TeleportPosition
		end
	end)
end

I found the problem
In the line:

local partToLookFor = v.A

Simply just remove the .A
v is already A. So A.A doesn’t exist.
That’s why its saying that
When you get children of the teleporters, it gets A, A, B.
for i,v runs the code on A then the other A then B not on the folder itself.
Keep that in mind

1 Like

Oh It works now thank you so much!

1 Like

Oh but I tried to duplicate it then it stopped working

It only works when I put the suitcase on the first teleporter then all of them starts to work…

What do you mean duplicate?
What exactly is your code supposed to do?

My code is to teleport a suitcase to the other teleporter and I also want to duplicate the teleporters without scripting it again to make it work

I don’t think I understand that. Maybe try making another thread and say the problem there?

alright thank you anyways!!!

1 Like