I was programming and I came across an error I have never seen before. I will show both the code and the error below.
This is the code
open = 0
Cstore = script.Parent.CFrame
local player = game.Players.LocalPlayer
function onClick()
if open == 0 then
if player.Backpack:FindFirstChild(script.Parent.ItemName.Value) then
open = 3
script.Parent.Open_Door:Play()
for i = 1,16 do
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0.25, 0, 0) * CFrame.fromEulerAnglesXYZ(0, math.rad(-5.625), 0)
end
open = 1
elseif open == 1 then
open = 3
for i = 1,16 do
wait(0.01)
script.Parent.Close_Door:Play()
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(-0.25, 0, 0.028) * CFrame.fromEulerAnglesXYZ(0, math.rad(5.625), 0)
end
script.Parent.CFrame = Cstore
open = 0
else
print("Player doesn't own key.")
end
end
end
script.Parent.ClickDetector.MouseClick:connect(onClick)
And this is the error:
18:07:09.974 - Workspace.LockedWithKeyDoor.TraditionalDoor.Door.Script:19: attempt to index upvalue 'player' (a nil value) 18:07:09.976 - Stack Begin 18:07:09.977 - Script 'Workspace.LockedWithKeyDoor.TraditionalDoor.Door.Script', Line 19 18:07:09.977 - Stack End.
I have no clue what went wrong. Any help is appreciated, Thanks!

3 comments
Done that, New error appeared. Workspace.LockedWithKeyDoor.TraditionalDoor.Door.Script:19: attempt to index global 'player' (a nil value)
Is this in a LocalScript?
No. I guess that's where I went wrong :P