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

Problem with :GetChildren()? Help?

Eh.. Idk what to type due to I never knew :GetChildren() is a nil on a Model... ;-;

OUTPUT : Spawns 09:03:48.262 - Workspace.Map:54: attempt to call method 'GetChildren' (a nil value) 09:03:48.263 - Stack Begin 09:03:48.264 - Script 'Workspace.Map', Line 54 - global Map 09:03:48.264 - Script 'Workspace.Map', Line 73 09:03:48.265 - Stack End

local DataTable={}
for _,a in pairs(game.Players:GetPlayers()) do
	for _,b in pairs(mv:GetChildren()) do
		if b.ClassName=='Model' and b.Name=='Spawns' then
			print(b.Name)
			for _,c in pairs(b.Name:GetChildren()) do
				print(c.Name)
				table.insert(DataTable,c.Position)
				local d=DataTable[math.random(1,#DataTable)]
				print(d)
				Teleport(d)
			end
		end
	end
end

1 answer

✓ Accepted answer
local DataTable={}
for _,a in pairs(game.Players:GetPlayers()) do
    for _,b in pairs(mv:GetChildren()) do
        if b.ClassName=='Model' and b.Name=='Spawns' then
            print(b.Name)
            for _,c in pairs(b:GetChildren()) do --Messed up here.
                print(c.Name)
                table.insert(DataTable,c.Position)
                local d=DataTable[math.random(1,#DataTable)]
                print(d)
                Teleport(d)
            end
        end
    end
end

The problem was that you put for _,c in pairs(b.Name:GetChildren()) do. All you need is "b" because it uses an object value, not a string value. More about :GetChilden()

2 comments

0

Thank you much!

0

You are welcome.

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