Atempt to index number with "GetChildren"

  1. What do you want to achieve? Keep it simple and clear!
    I want to make it so you can weld the contents of any model to a part inside of that model except the part being welded to

  2. What is the issue? Include screenshots / videos if possible!
    Module script:

local Functions = {}

Functions.WeldModelToPart = function(Model,Part)
	for _,v in pairs(Model:GetChildren()) do
		if v:IsA("BasePart") and not (Part) then
			local WeldConstraint = Instance.new("WeldConstraint")
			WeldConstraint.Part0 = v
			WeldConstraint.Part1 = Part
			WeldConstraint.Parent = WeldConstraint.Part0

			v.Anchored = false
		end
	end
end

return Functions

Function that calls it:

local Mainsystem = require(game.ServerScriptService.MainsystemBase)
wait(1)
spawn(Mainsystem.WeldModelToPart)(workspace.CoreFolder.ControlRoomGlassCover.Door1,workspace.CoreFolder.ControlRoomGlassCover.Door1.Primary)

The error is:

  20:47:17.829  ServerScriptService.MainsystemBase:6: attempt to index nil with 'GetChildren'  -  Server - MainsystemBase:6

Not sure why this is happening, But all locations are correct

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Yes actually, but none of them seemed to work
1 Like

spawn does not pass the arguments, you must use a coroutine

coroutine.wrap(Mainsystem.WeldModelToPart)(workspace.CoreFolder.ControlRoomGlassCover.Door1,workspace.CoreFolder.ControlRoomGlassCover.Door1.Primary)
1 Like

You need to call the coroutine directly after indexing it with a variable

local f = coroutine.wrap(function)
f(...)
1 Like

That’s when the coroutine is created/stored, but I’m creating and calling it on one line, it’s like what happens when you connect a function.
this

local Print = coroutine.wrap(function()
	print("A")
end)
Print()

is the same as this

coroutine.wrap(function()			print("A")				end)()

with connections

function Print()
    print("A")
end
workspace.Part.Touched:Connect(Print)

workspace.Part.Touched:Connect(function()
    print("A")
end)
1 Like

I tried this too i did

couroutine.wrap(Mainsystem.WeldModelToPart)(workspace.CoreFolder.ControlRoomGlassCover.Door1,workspace.CoreFolder.ControlRoomGlassCover.Door1.Primary)

But it did the same error
Anyways i need to go to bed

You must to call spawn() first with a dummy function, then call the module with the arguments:
As spawn() do not accept any parameters passed into it.

spawn(function()
   module.WeldFunction(...)
end)
2 Likes

Sorry guys! i typed the error wrong, It was supposed to be index number with “GetChildreN”

The error message does not change your incorrect function syntax; spawn a new function, then call the weld function inside that newly spawned function.

1 Like