-- Detect player within zone and flash parts

local sensor = script.Parent.Parent.Door.Sensor
while wait() do
	local shouldOpen = false
	for _, Player in pairs(game.Players:GetPlayers()) do
		if (Player.Character and Player.Character:FindFirstChild("HumanoidRootPart") and (Player.Character.HumanoidRootPart.Position - sensor.Position).magnitude < 10) then
			shouldOpen = true
			break
		end
	end
	-- Flash parts
	if shouldOpen and not Open then
		Open = true 
		DoorLogo.Beep:Play()
		Flash("Bright green") 
		Move(true) 
	elseif not shouldOpen and Open then
		Open = false
		Move(false)
		DoorLogo.Beep:Play()
		Flash("Bright red")
	end
end
