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

GetChildren returning an empty table?

When i try to get the children of a model in workspace, it just returns an empty table. Anyone know why this is happening?

Note: I am using inspect module to print out the contents of the table.

local inspect = require(workspace.inspect)
local Model = Instance.new("Model",workspace)

print("up to waiting")
repeat wait() print("Waiting") until workspace:FindFirstChild("Model")






while wait(1) do
Model = workspace.Model:GetChildren()
print(inspect(Model))
end

Gif link: https://gyazo.com/d068e68f2cd4efaf75a2feaead88425b

Edit: items are added to the model via a tool. Both files are localscripts if that helps in any way.

Edit 2: Request for my tool script. Ill provide it but it is very convoluted as i was testing alot of things in that one script file. In essence, the script just adds a part the model with welding capabilities.

local UserInputService = game:GetService("UserInputService")
local Tool = script.Parent
xSize = 3
ySize = 1
zSize = 5
Mouse = game.Players.LocalPlayer:GetMouse()

newBlock = nil
--local Model = Instance.new("Model",workspace)

function createSingleInstance()
--	print(Mouse.Target)
--	print(type(Mouse.Target))
	if Mouse.Target.Name ~= "Block" then

		local groundBlock = Instance.new("Part",workspace.Model)
		groundBlock.Name = "Block"
		groundBlock.Anchored = true
		groundBlock.Size = Vector3.new(xSize,ySize,zSize)
		groundBlock.Material = Enum.Material.Plastic
		groundBlock.Transparency = 1
		groundBlock.Position = Mouse.Hit.p
		
		groundBlock.BackSurface = Enum.SurfaceType.Smooth
		groundBlock.BottomSurface = Enum.SurfaceType.Smooth  
		groundBlock.FrontSurface = Enum.SurfaceType.Smooth    
		groundBlock.LeftSurface = Enum.SurfaceType.Smooth    
		groundBlock.RightSurface = Enum.SurfaceType.Smooth 
		groundBlock.TopSurface = Enum.SurfaceType.Smooth 

		groundBlock.Transparency = .9
		wait (.01)
		groundBlock.Transparency = .8
		wait (.01)
		groundBlock.Transparency = .7
		wait (.01)
		groundBlock.Transparency = .6
		wait (.01)
		groundBlock.Transparency = .5
		wait (.01)
		groundBlock.Transparency = .4
		wait (.01)
		groundBlock.Transparency = .3
		wait (.01)
		groundBlock.Transparency = .2
		wait (.01)
		groundBlock.Transparency = .1
		wait (.01)
		groundBlock.Transparency = 0

	elseif Mouse.Target.Name == "Block" then
	
		local newBlock = Instance.new("Part",workspace.Model)
		local target = Mouse.Target
		newBlock.Name = "Block"
		newBlock.Anchored = false
		newBlock.Size = Vector3.new(3,3,3)
		newBlock.Transparency = 0
		newBlock.Position = Mouse.Hit.p -- nearest surface?
		
		newBlock.BackSurface = Enum.SurfaceType.Weld  
		newBlock.BottomSurface = Enum.SurfaceType.Weld  
		newBlock.FrontSurface = Enum.SurfaceType.Weld  
		newBlock.LeftSurface = Enum.SurfaceType.Weld  
		newBlock.RightSurface = Enum.SurfaceType.Weld
		newBlock.TopSurface = Enum.SurfaceType.Weld
		
		--newBlock.CFrame = target.CFrame.Angles --* CFrame.new(0, newBlock.Size.Y / 2 + otherBlock.Size.Y / 2, 0)
		--wait(0.1)
		--newBlock.Anchored = false
		wait(0.01)
		local weld = Instance.new("WeldConstraint")
		weld.Parent = workspace.Model
		weld.Part0 = target
		weld.Part1 = newBlock

		---[[
		newBlock.Transparency = .9
		wait (.01)
		newBlock.Transparency = .8
		wait (.01)
		newBlock.Transparency = .7
		wait (.01)
		newBlock.Transparency = .6
		wait (.01)
		newBlock.Transparency = .5
		wait (.01)
		newBlock.Transparency = .4
		wait (.01)
		newBlock.Transparency = .3
		wait (.01)
		newBlock.Transparency = .2
		wait (.01)
		newBlock.Transparency = .1
		wait (.01)
		newBlock.Transparency = 0
				--]]
	end


end




function unAnchor(brick)
	if brick.Name ~= "Baseplate" then--and game.Players.LocalPlayer.Backpack.Flying_Float_Tool then
	brick.Anchored = false
---[[	
	wait(0.5)
	brick:Destroy()
	print("part Destroyed")
	end
end




function killHuman(touchedPart) 	
		if touchedPart.Name ~= "Baseplate" then
			
		humanoid.Health = 0
		end
end



-- If tool is used command --
Tool.Activated:Connect(createSingleInstance)

-- Block Destroyer --
wait(1)
repeat wait() until game.Players.LocalPlayer.Character
humanoid = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid")

humanoid.Touched:Connect(unAnchor)	

2 comments

1

Is it a LocalScript? FE might be a affecting your script

0

Can we see the module script, the problem might be there

2 answers

✓ Accepted answer

You’re probably making the model — in the first script — from a server script, which allows the model to replicate to all the clients. However, when you insert objects in this model — from the local script, the objects will not replicate since they have been created locally and changes made by clients rarely replicate to the server. This results in the server observing no children in the model. To overcome this you can use use remotes.

Learn more about replication here

Eh not sure im fully understanding this, but isnt it because you created a model using Instance.new and parent it to workspace but didnt put anything in it?

all you did is create an empty model

judging by your explorer window you want to find an already existing model instead of creating a new one

so instead of local Model = Instance.new("Model",workspace)

i think you might need `local Model = workspace:WaitForChild("Model")

1 comment

0

Im adding items to it via a tool

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