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

Attempt to index nil error with door?

Asked by 3 years ago

I have made a table in order to reference objects quicker. The problem is that an error occurs where it says, "Attempt to index nil with door1". I am wondering if someone could point out what is wrong so I can fix it.

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 Door = DoorGroup.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)

1 answer

Log in to vote
0
Answered by 3 years ago

The error is coming from the lines below. DoorGroup.PrimeDoor does not exist; therefore, you are indexing nil with Door1.

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

local Door = DoorGroup.PrimeDoor
local DoorPart = Door.Door1
0
But the problem is that it does exist. I have checked and both of them have the PrimeDoor and Door1. Nexxive25 27 — 3y
Ad

Answer this question