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
Is it a LocalScript? FE might be a affecting your script
Can we see the module script, the problem might be there