Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

GetChildren() is calling a nil value?

Asked by 3 years ago

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

Log in to vote
1
Answered by 3 years ago

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.

Ad
Log in to vote
0
Answered by 3 years ago

I am sure these people can help you, they are teaching and helping people with Roblox Lua for free. I personally love it, and it helped me with a lot of errors: https://discord.gg/MPnhU2aCSb

Log in to vote
0
Answered by 3 years ago

You can only do :GetChildren() with an instance

Since its a normal table you can just use DoorGroup

Answer this question