Door Script not Working after Checks

I have a door system and a leaning system. The leaning system moves the players camera to look out the doorway. Of course, if the door is shut, the player shouldn’t be able to do this. I decided the best way to implement this would be a Bool Value. Every time the door is shut, the value will be set to true, and when it is opened the value will be set to false.

In the lean script, I made sure to check the value, and if it is false, the player can lean. Unfortunately, the script isn’t working and I can’t seem to figure out why.

(Local Script) Lean Script:

	if input.KeyCode == Enum.KeyCode.E and doorCheck == false and leaning == false then
		leaning = true
		print("Leaning out.")
	elseif input.KeyCode == Enum.KeyCode.E and doorCheck == false and leaning == true then
		leaning = false
		print("Leaning in.")
	elseif input.KeyCode == Enum.KeyCode.E and doorCheck == true then
		print("The door is shut.")

Note: This isn’t the full script. It worked fine before I implemented the “and doorCheck”.

(Script) Door Button Script:

function onMouseClick()
	if isDoorOpen == true and debounce == false then
		debounce = true
		isDoorOpen = false
		officeLight.Color =, 0.34902, 0.34902)
		button.Color =, 1, 0.360784)
		button.Light.Color =, 1, 0.360784)
		doorCheck.Value = true
		debounce = false

ˢᵒʳʳʸ ᵃᵇᵒᵘᵗ ᵗʰᵉ ᵐᵉˢˢʸ ᶜᵒᵈᵉ

The problem is that the lean script doesn’t work whether the door is closed or not. My guess is that I’m just dumb and Bool Values don’t actually work between local and server scripts, so let me know.

The answer is pretty simple, you’re using a LocalScript to run code on a ServerScript.
This can’t work.
There’s a few ways to work around this, but the easiest one is to have the LocalScript fire an event on the server.

local ServerSide = script.Parent.ServerSide

local function onClick()
    -- fire event on server


Then, you can make the server listen to this event and run the code:

local EventClicked = script.Parent.Clicked

local function onClicked()
    -- run code


I would think that Bool Value would kinda act like a remote event. It’s in a place that both scripts can access, and both scripts can read, atleast I thought. Also, how would I do a remote event for a constant action rather than a 1 time trigger?

You’re not resetting isDoorOpen back to true after setting it to false, the first time it runs.

The door is a button toggle, and like I said these are only small portions of the scripts. My problem is I’m not sure why I can’t lean no matter if the doorCheck is true or false.