I have encountered an error in line 12 of my script. It says, "attempt to index nil with 'Door1'" Can someone tell me why it is not working? I have used a table to reference multiple objects btw. I have checked the doors and they are both identical.
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)

2 comments
On line 11 you're defining "Door" as DoorGroup.PrimeDoor, however there is no variable in DoorGroup for PrimeDoor? Not sure if that's the issue or if I'm just being stupid haha
yeah thats the issue, also when you want to use a string as a key for a table, you define it like this: ["key"] = value, otherwise it will default to using numbers as keys