[help] Checking door state in server main?

So I’m making a script for bank robbing and I have it so the door opens client side, How do i make it so the server checks if it is open or not? since i want multiple people to be able to go down to the vault, i currently have this in my client main:

Citizen.CreateThread(function()
  while true do
		Citizen.Wait(0)
		DrawMarker(20, 262.0, 223.08, 107.28, 0.0, 0.0, 0.0, 180.0, 0.0, 0.0, 0.5, 0.5, 0.5, 255, 0, 0, 55, true, true, 2, false, nil, nil, false)
		BankDoor = GetClosestObjectOfType(262.1981, 222.5188, 106.4296, 100.0, 746855201, 0, 0, 0)
		FreezeEntityPosition(BankDoor, IsLocked)
		--GetEntityHeading(BankDoor)
		--SetEntityHeading(BankDoor, DoorH)
  end
end)

My server main is empty atm.
Any help is greatly appreciated
Cheers

So what you can do is make an toggle door lock event, you don’t have to put it in a while loop by the way, you can use it in these events

client:

-- Set status for every client
RegisterNetEvent('bankrobbing:SetDoorStatus')
AddEventHandler('bankrobbing:SetDoorStatus', function(LockStatus)
     BankDoor = GetClosestObjectOfType(262.1981, 222.5188, 106.4296, 100.0, 746855201, 0, 0, 0)
     FreezeEntityPosition(BankDoor, LockStatus)
end)

server:

local DoorStatus = true
RegisterServerEvent('bankrobbing:ToggleDoorStatus')
AddEventHandler('bankrobbing:ToggleDoorStatus', function()
     DoorStatus = not Doorstatus
     TriggerClientEvent('bankrobbing:SetDoorStatus', -1, DoorStatus)
end)

and then you can just trigger it by: TriggerServerEvent('bankrobbing:ToggleDoorStatus')

Thanks for the reply!
Will try this as soon as i can thank you so much for the help!

So I’ve done what you said and tried it but the door is not locking now, ive also added a draw marker into the Handler like this

RegisterNetEvent('bankrob:SetDoorStatus')
AddEventHandler('bankrob:SetDoorStatus', function(LockStatus)
	DrawMarker(20, 262.0, 223.08, 107.28, 0.0, 0.0, 0.0, 180.0, 0.0, 0.0, 0.5, 0.5, 0.5, 255, 0, 0, 55, true, true, 2, false, nil, nil, false)
    BankDoor = GetClosestObjectOfType(262.1981, 222.5188, 106.4296, 100.0, 746855201, 0, 0, 0)
    FreezeEntityPosition(BankDoor, LockStatus)
end)

and no marker shows so im guessing ive done something wrong?

Ye, a marker need to be in the whileloop however the bankdoor and freezeentity don’t

did you make a mistake with the LockStatus and DoorStatus should they be the same or? i just dont understand it, the door is not locked by default, and after i trigger nothing happens.

Never mind ive solved it, I have the door (entity) frozen in a loop and the trigger just changes the heading of the door now thanks for showing me the right direction buddy