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 comment
But the problem is that it does exist. I have checked and both of them have the PrimeDoor and Door1.