Touch 3 Parts to open door

Hello, I’m trying to touch 3 parts to open a door. All 3 Parts need to be touched for the door to open. The error I get is in line 8 which says “Attempt to call a nil value”. What is wrong in line 8?

local part1 = workspace.Part1

local part2 = workspace.Part2
local part3 = workspace.Part3
local touchedPart1 = false
local touchedPart2 = false
local touchedPart3 = false

local player = GetService(Players).LocalPlayer
local character = player.CharacterAdded:Wait()
player.CharacterAdded:Connect(function(char)
character = char
end)
local door = workspace.Door

part1.Touched:Connect(function(hit)
if hit.Parent == character then
partTouched1 = true
end

if partTouched2 and partTouched3 then
	door.Transparency = 0.5
	door.CanCollide = false
end

end)

part2.Touched:Connect(function(hit)
if hit.Parent == character then
partTouched2 = true
end

if partTouched1 and partTouched3 then
	door.Transparency = 0.5
	door.CanCollide = false
end

end)

part3.Touched:Connect(function(hit)
if hit.Parent == character then
partTouched3 = true
end

if partTouched2 and partTouched3 then
	door.Transparency = 0
	door.CanCollide = false
end

end)

You can just do this

local player = game.Players.LocalPlayer

Just to make sure, I was supposed to delete line 9 right? I got this error "attempt to index nil with ‘Character’ "

The player was not found, so that the script is unable to get the character and thats why you get the error

Well do this actually

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
player.CharacterAdded:Connect(function(char)
character = char
end)

This is my new script when I add that part. Hopefully I added the right part in the right place as I get this " attempt to index nil with ‘Character’"

local part1 = workspace.Part1
local part2 = workspace.Part2
local part3 = workspace.Part3
local touchedPart1 = false
local touchedPart2 = false
local touchedPart3 = false

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
player.CharacterAdded:Connect(function(char)
character = char
end)
local door = workspace.Door

part1.Touched:Connect(function(hit)
if hit.Parent == character then		
	partTouched1 = true
end

if partTouched2 and partTouched3 then
	door.Transparency = 0.5
	door.CanCollide = false
end
 end)

part2.Touched:Connect(function(hit)
if hit.Parent == character then
	partTouched2 = true
end

if partTouched1 and partTouched3 then
	door.Transparency = 0.5
	door.CanCollide = false
end
end)

part3.Touched:Connect(function(hit)
if hit.Parent == character then
	partTouched3 = true
end

if partTouched2 and partTouched3 then
	door.Transparency = 0
	door.CanCollide = false
end
end)

You wrote touchedPart1, touchedPart2 and touchedPart3 at the top
and then you wrote partTouched1, partTouched2 and partTouched3.

When I change that I still get "attempt to index nil with ‘Character’ "

An easier approach would be to put all of the Parts inside a Folder, then get them using the GetChildren() function which will return back a table, then you can detect what parts have been Touched & what hasn’t, then check through a loop if all of the PartsRemaining are equal to 0:

local Parts = workspace.PartFolder
local Door = workspace.Door
local RunService = game:GetService("RunService")
local PartsRemaining = #Parts --Or 3

for _, Part in pairs(Parts:GetChildren()) do
    local PartDebounce = false

    Part.Touched:Connect(function(Hit)
        local HitPlayer = game.Players:GetPlayerFromCharacter(Hit.Parent)

        if HitPlayer and not PartDebounce then
            PartDebounce = true
            PartsRemaining -= 1
        end
    end)
end

while true do
    if PartsRemaining == 0 then
        Door.Transparency = 0.5
        Door.CanCollide = false

        break
    end
    RunService.RenderStepped:Wait()
end

Also if this isn’t in a LocalScript like @aquawrsp mentioned I swear I’m gonna break 500 keyboards

You are doing it in a localscript right

Yes!!! It worked!! I went to Starter Player, starter Character Scripts, Local Script and put the code there!! Thanks!!!.

Since this will only work for that particular player, how can I make it to where once a player does this, the door will be open for everyone?