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

GetChildren() is calling a nil value?

So in my door, I have compiled a table to make it easier for me to reference objects, and then I made a value that named all the children in that table, but it gives me an "Attempt to call nil value" error.

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

local DoorGroup = {
	game.Workspace.ButtonDoor,
	game.Workspace.ButtonDoor1
}

local DoorGroupChildren = DoorGroup:GetChildren() 
local Door = DoorGroupChildren.PrimeDoor
local DoorPart = Door.Door1
local DoorPrimaryPart = Door.PrimaryPart

local neonpart = Door.Button.Neon

local player = game.Players.LocalPlayer
local event = game.ReplicatedStorage.ToggleDoor
local mouse = player:GetMouse()

local NearDoor = false

RunService.RenderStepped:Connect(function()
	if Player:DistanceFromCharacter(DoorPrimaryPart.Position) < 5 then
		if mouse.Target == DoorPrimaryPart then
			NearDoor = true
			DoorPrimaryPart.EToOpen.Enabled = true
			DoorPrimaryPart.EToOpen2.Enabled = true
		end
	else
		NearDoor = false
		DoorPrimaryPart.EToOpen.Enabled = false
		DoorPrimaryPart.EToOpen2.Enabled = false
	end
end)

UserInputService.InputBegan:Connect(function(Input)
	if Input.UserInputType == 	Enum.UserInputType.Keyboard then
		local Key = Input.KeyCode
		if Key == Enum.KeyCode.E and NearDoor == true then
			event:FireServer()
		end
	end
end)


3 answers

Hello, it's because DoorGroup is already a table defined at Line 06 - 09. GetChildren() returns a table of an instance's childrens. But DoorGroup is already a table and it doesn't even have any children. I hope this helps.

You can only do :GetChildren() with an instance

Since its a normal table you can just use DoorGroup

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