-- Handle event fire

local function toggleDoor(player, door)
	
	-- Check distance to the character's Torso. If too far, don't do anything
	if player.Character and player.Character:FindFirstChild("Torso") then	
		local torso = player.Character:FindFirstChild("Torso")
		local toTorso = torso.Position - stove.Door.Position
		if toTorso.magnitude < clickDistance then
			if open then
				ovenMotor.DesiredAngle = 0
				open = false
			else
				ovenMotor.DesiredAngle = math.pi/2
				open = true
			end
		end
	end
end

stove.DoorPadding.ROBLOXInteractionEvent.OnServerEvent:connect(function(player, arguments)
	toggleDoor(player)
end)

stove.Door.ROBLOXInteractionEvent.OnServerEvent:connect(function(player, arguments)
	toggleDoor(player)
end)
