I have this script that opens a door via using CFrame and by using a click detector, however when I click the door it produces and error in the output:
Workspace.Door.Script:11: attempt to index upvalue 'door' (a function value)
Heres the code btw:
local hinge = script.Parent:WaitForChild("Hinge") local door = script.Parent:WaitForChild("Door") local closed = true local hingePosition = hinge.Position function door() if closed then local degrees = 90 * (tick() % 1)/1 door.CFrame = CFrame.new(hingePosition) * CFrame.Angles(0, math.rad(degrees), 0) * CFrame.new(0.6, 0, 0) wait(1) closed = false elseif not closed then local degrees = 0 * (tick() % 1)/1 door.CFrame = CFrame.new(hingePosition) * CFrame.Angles(0, math.rad(degrees), 0) * CFrame.new(0.6, 0, 0) wait(1) closed = true end end script.Parent.ClickDetector.MouseClick:Connect(door)
I checked the wiki for the error and it says that its caused by giving the operation the wrong variable, however i dont understand why or how my variable door is an incorrect variable in this case
Rename the door() function to doorToggle() or something else